85
rated 0 times
[
87]
[
2]
/ answers: 1 / hits: 38206
/ 8 Years ago, wed, august 31, 2016, 12:00:00
How can I get top 5 max elements from array of ints with the standard library of es2015? Thanks for help.
More From » arrays
How can I get top 5 max elements from array of ints with the standard library of es2015? Thanks for help.
A solution in ES6 :
values = [1,65,8,98,689,12,33,2,3,789];
var topValues = values.sort((a,b) => b-a).slice(0,5);
console.log(topValues); // [789,689,98,65,33]
Many others exist, ask if you need more