DEV Community

loading...

Discussion on: Daily Challenge #278 - Find all non-consecutive numbers

Collapse
kylejschwartz profile image
Kyle Schwartz

JavaScript solution in 5 lines

const nconsecutive = arr => {
    const arr2 = [];
    arr.forEach((n, i) => (i > 0 && n - 1 !== arr[i-1]) ? arr2.push({i, n}) : false);
    return arr2;
}
Collapse
mintypt profile image
mintyPT • Edited

You could do it in one :)