DEV Community

loading...

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

Collapse
rafi993 profile image
Rafi

Ruby

def nconsecutive(array)
 prev = array[0]
 output = []
 array.drop(1).each_with_index do | i, index |
    if prev + 1 != i
        output.push({ i: i, n: index + 1 })
    end
    prev = i
 end

 return output
end