const getMaxIndexes = (arr, count) => Object
.entries(arr.reduce((acc, n, i) => ((acc[n] = acc[n] ?? []).push(i), acc), {}))
.sort((a, b) => b[0] - a[0])
.flatMap(n => n[1])
.slice(0, count);
const getTopIndexes = (arr, count) => {
return arr.reduce((topIndexes, v, i, arr) => {
let insertIndex = topIndexes.length
for (let ind = topIndexes.length - 1; ind >= 0; ind --)
if (v > arr[topIndexes[ind]]) insertIndex = ind
else break
topIndexes.splice(insertIndex, 0, i)
return topIndexes.slice(0, count)
}, [])
}
console.log(getTopIndexes([-7, 2, 7, 5, 1, 4, -5, 7], 3)) // 2, 7, 3