Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8825755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:57:17+00:00 2026-06-14T06:57:17+00:00

I have an array filled with positive int values, how could I normalize this

  • 0

I have an array filled with positive int values, how could I normalize this list so the max value is always 100? Thank you in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T06:57:18+00:00Added an answer on June 14, 2026 at 6:57 am

    The idea is to first find the highest number in your array (using apply on Math.max), then find the ratio between that highest number and 100.

    After that, it’s just a matter of looping through your array and dividing all your numbers by that ratio:

    var numbers = [3, 8, 45, 74, 123],
        ratio = Math.max.apply(Math, numbers) / 100,
        l = numbers.length,
        i;
    
    for (i = 0; i < l; i++) {
        numbers[i] = Math.round(numbers[i] / ratio);
    }
    

    Here’s the fiddle: http://jsfiddle.net/XpRR8/


    Note: I’m using Math.round to round the numbers to the nearest integer. If you instead prefer to keep them as floats, just remove the function call:

    for ( i = 0; i < l; i++ ) {
        numbers[i] /= ratio;
    }
    

    Here’s the fiddle: http://jsfiddle.net/XpRR8/1/


    If you don’t have to support IE8 and below, you can use Array.prototype.map():

    var numbers = [3, 8, 45, 74, 123],
        ratio = Math.max.apply(Math, numbers) / 100;
    
    numbers = numbers.map(function (v) {
        return Math.round(v / ratio);
    });
    

    Here’s the fiddle: http://jsfiddle.net/XpRR8/2/


    If you do support IE8, but are anyhow using jQuery, you can use $.map() instead:

    numbers = $.map(numbers, function (v) {
        return Math.round(v / ratio);
    });
    

    Here’s the fiddle: http://jsfiddle.net/XpRR8/3/


    Update: As pointed out by @wvxvw in the comments below, if you’re concerned about fringe implementations that impose an artificial limit on the amount of arguments apply will handle, then use a loop instead of Math.max.apply. Here’s an example (assuming neither Array.prototype.map nor $.map are available):

    var numbers = [3, 8, 45, 74, 123],
        ratio = 0,
        i = numbers.length;
    
    while (i--) numbers[i] > ratio && (ratio = numbers[i]);
    
    ratio /= 100;
    i = numbers.length;
    
    while (i--) numbers[i] = Math.round(numbers[i] / ratio);
    

    Here’s the fiddle: http://jsfiddle.net/XpRR8/4/


    If you’re using ES6, this becomes laughably simple:

    var numbers = [3, 8, 45, 74, 123];
    var ratio = Math.max(...numbers) / 100;
    
    numbers = numbers.map(v => Math.round(v / ratio));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array and filled its values like that: $('#list input:checked').each(function() { deleteRecordIdsStr.push($(this).attr('name'));
I have one array that is filled by mysql_query. Values that are in this
I have an array filled with paths looking like this: library/main/single/list.php library/article/grid/thumbs.php library/footer/tiny.php These
I have an assoc array filled with the values necessary for a PDOstatement. Should
I have an array filled with strings, a value can for example be not
Suppose I have an array filled with Boolean values and I want to know
I have an javascript array filled with values of checkboxes in a html file.
I have an array filled with values (twitter ids) and I would like to
I have an array that is filled with values dynamically and I have to
I have dynamic array filled with bytes, which are read from .raw file with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.