You are viewing a single comment's thread. Return to all comments →
The first one is indeed overly complex, as it would search the max at each iteration
I used the reduce function instead, which allows for a single iteration, provided an extra local variable, like so
function birthdayCakeCandles(ar) { let max = 0; return ar.reduce( (count, i) => i === max ? count + 1 : i > max ? (max = i) && 1 : count, 0 ); }
Seems like cookies are disabled on this browser, please enable them to open this website
Birthday Cake Candles
You are viewing a single comment's thread. Return to all comments →
The first one is indeed overly complex, as it would search the max at each iteration
I used the reduce function instead, which allows for a single iteration, provided an extra local variable, like so