DEV Community

Discussion on: Daily Challenge #152 - Strongest Number in an Interval

Collapse
 
vitornogueira profile image
Vitor Nogueira • Edited
const calcMaxStrength = (numbers) => {
  const divider = 2;

  const isOdd = number => number % 2 === 0;

  const calcStrength = (dividend, strength = 0) => {
    if (isOdd(dividend)) {
      return calcStrength(dividend / divider, strength += 1);
    }

    return strength;
  };

  return Math.max(...numbers.map(number => calcStrength(number)));
};

console.log(calcMaxStrength([48, 56])); // 4
console.log(calcMaxStrength([129, 193])); // 0