JS arithmetic group average, maximum, minimum, deviation, standard deviation, median, array from small to large sort, up four, next four

Source: Internet
Author: User
Tags array sort

The array to be counted is named data

 var sum = function  (x, y) {return x+y;};   sum function var square  = function  (x) {return x*x;};  Each element in the array asks for its square var data  = [1 , 1 , 3 , 5 , 5 ]; var mean  = data.reduce (sum)/data.length;var Deviations  = Data.map (function  (x) {return x mean;}); var StdDev  = math.sqrt (Deviations.map (square). reduce (sum)/(Data.length-1   = Math.max.apply (Null,data) var Min  = Math.min.apply (null,data)  
 var compare = function (x, y) {//Comparison function 
if (x < y) {
return-1;
} else if (x > Y) {
return 1;
} else {
return 0;
}
};
var mid;//median
Data.sort (compare);//Array sort
if (data.length%2==0) {
Mid = (data[data.length/2]+data[ DATA.LENGTH/2+1])/2
}
if (data.length%2!=0) {
mid = data[(data.length+1)/2]
}
Console.log (" average value:" +mean);
Console.log (" deviation:" +deviations);
Console.log (" standard deviation:" +stddev);
Console.log (" maximum value:" +max);
Console.log (" Minimum Value:" +min);
Console.log ("median:" +mid);
Console.log ("top four min.:" +DATA[DATA.LENGTH/4]);
Console.log ("The next four cents:" +data[data.length/4*3]);






JS arithmetic group mean, maximum, minimum, deviation, standard deviation, median, array from small to large, top four, next four

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.