We're a place where coders share, stay up-to-date and grow their careers.
And if you really want the best possible perfs, the best option is to iterate once.
It could go like that:
let count = 0; for (let i = 0, max = 0, n = arr.length; i<n; i++) { if (arr[i] > max) { max = arr[i]; count = 1; } else if (arr[i] === max) { count++; } } return count;
And if you really want the best possible perfs, the best option is to iterate once.
It could go like that: