← Back to challenges

Count 5s and Win

JavaScriptHardalgorithmsarrays

Instructions

Arun is obsessed with primes, especially five. He considers a number to be luckiest if it has the highest number of five in it. If two numbers have the same frequency of five, Arun considers the larger of them to be luckiest, and if there is no five in any number, the first given number is considered luckiest. Help him choose the luckiest number.

Examples

getLuckiest([5, 12, 55, 11]) ➞ 55

getLuckiest([5, 12, -55,  11]) ➞ -55

getLuckiest([515, 1255, -55,  1]) ➞ 1255

getLuckiest([44, 12, 7, 40]) ➞ 44

Notes

Return null if given an empty array.

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.