DEV Community

Discussion on: What’s your alternative solution? Challenge #1

Collapse
 
neiker profile image
Javier Alvarez

Please do not try this at home.

function count(limit, current = 1) {
    if (current < limit) {
        return [current, ...count(limit, ++current)];
    }

    return [current];
}

console.log(count(10));
Enter fullscreen mode Exit fullscreen mode