# Can someone show me a function that

**URL:** <https://forum.kirupa.com/t/can-someone-show-me-a-function-that/174981>\
**Category:** Uncategorized\
**Created:** [January 10, 2006, 8:14pm UTC](https://forum.kirupa.com/t/can-someone-show-me-a-function-that/174981 "2006-01-10T20:14:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dragonfly](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@dragonfly](https://forum.kirupa.com/u/dragonfly)\
**Post date:** [January 10, 2006, 8:14pm UTC](https://forum.kirupa.com/t/can-someone-show-me-a-function-that/174981/1 "2006-01-10T20:14:37Z")

</div>

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!
