JSFiddle - React, Tailwind, and code Playground
JavaScript
function get_top_10(list) {
var top10 = new Array(10).fill(0)
for(i in list) {
var smallest_in_top10 = Math.min.apply( Math, top10 )
if(list[i] > smallest_in_top10) {
top10.splice(top10.indexOf(smallest_in_top10),1)
top10.push(list[i])
}
}
return top10
}
console.log(get_top_10([1,2,3,4,5,6,7,8,9,10,11,12]))
var random_list = [];
for (var i = 0; i < 100; i++) {
random_list.push(Math.round(Math.random() * 999999))
}
console.log(get_top_10(random_list))
function sortNumber(a,b) {
return a - b;
}