I have an unsorted array (of generated die rolls), and I want to select the top N elements of it (which is trivial with sort-and-snip), but mark them while keeping them in order.
E.g.:
mark([1,2,3,4], 3) ==> [[1, false], [2, true], [3, true], [4, true]]
mark([3,5,2,6,2], 3) ==> [[3, true], [5, true], [2, false], [6, true], [2, false]]
The array may contain any values from 1 up, and be of any length, and the amount of marked elements is variable.
I could live with
mark([3,5,2,6,2], 3) ==> [[3, true], [5, true], 2, [6, true], [2, true]]
(I.e., numbers that'd be marked false to go unmarked), but I'd rather avoid it.
What's mandatory is that the order of the array stays unchanged.
If the top elements are repeated (eg: top 3 of [6,6,6,6,6,6]), mark the first 3 elements.
(N is sufficiently small for complexity not to matter much.)
EDIT: Bonus point: add a parameter to switch between "top" and "bottom" mode.