Normalize a list of positive numbers in JavaScript - Javascript jQuery

Javascript examples for jQuery:Number

Description

Normalize a list of positive numbers in JavaScript

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <script type="text/javascript" src="https://code.jquery.com/jquery-1.8.3.js"></script> 
  <script type="text/javascript">
    $(window).load(function(){/*w w  w  .ja  v a 2 s. co m*/
var numbers = [3, 8, 45, 74, 123,123,432,12,123,123,12,3,123,],
    ratio = Math.max.apply(this, numbers) / 100;
numbers = $.map(numbers, function (v) {
    return Math.round( v / ratio );
});
console.log(numbers);
    });

      </script> 
 </head> 
 <body>  
 </body>
</html>

Related Tutorials