loading...

re: Daily Challenge #152 - Strongest Number in an Interval VIEW POST

FULL DISCUSSION
 

Hello guys, this is my first time here, and this is my recursive approach:

function strongest(from, to, times = 0) {
    if (from > to) return false;
    if (to - from < 1) return from * (2 ** times);
    if (to - from < 2) return (from + (from % 2)) * (2 ** times);
    return strongest((from + (from % 2)) / 2, (to - (to % 2)) / 2, times + 1);
}

EDIT without times:

function strongest(from, to) {
    if (from > to) return false;
    if (to - from < 1) return from;
    if (to - from < 2) return from + (from % 2);
    return 2 * strongest((from + (from % 2)) / 2, (to - (to % 2)) / 2);
}
code of conduct - report abuse