Can someone show me a function that

After sorting an array of, say, 10 values in decending order, i want to obtain the top 3 values and put them in a new array.

Now, i don’t mean just slice the first 3 elements off the array (because its sorted in decending order). Some of the values may be the same…all of them might even be the same, in which case i would need to obtain all of the values.

So if i have [9, 8, 8, 7, 7, 7, 6, 3, 2, 2] … I need to return [9, 8, 8, 7, 7, 7] because these are the top 3 values.

I’m using a series of if…then statements now, but this is a bit sloppy and hard to scale.

Thanks for any help!