How would one list the top 5 (or different number, such as three or ten) largest numbers in an array?

Say you had an array like:

let array = [1, 9, 12, 50, 74, -34, -1] // with the expected output: 74, 50, 12, 9, 1

How would one sort the top 5 largest numbers using javascript?

40 thoughts on “How would one list the top 5 (or different number, such as three or ten) largest numbers in an array?”

Leave a Comment