If, as you seem to indicate in a comment to your question, you just want those greater than the third quartile, it's easy.
Simply create a sorted list of the N
numbers and then get those above the 3N/4
index position.
You can use Array.sort()
to sort the array, Array.length
to get the length and Array.slice()
to extract a slice of the array.
For example, the following code:
var set = new Array(1, 2, 1, 2, 3, 9, 12, 15);
document.write(set);
set.sort(function(a, b){return a-b});
document.write('<br>');
document.write(set);
var len = set.length;
document.write('<br>');
document.write(len);
var topQ = set.slice (3*len/4);
document.write('<br>');
document.write(topQ);
outputs the unsorted and sorted list, the length, and the top 25%:
1,2,1,2,3,9,12,15
1,1,2,2,3,9,12,15
8
12,15