Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions codewars/8kyu/find-the-first-non-consecutive-number/koronya.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// [JS][8kyu] Find the first non-consecutive number
// find-the-first-non-consecutive-number
// https://www.codewars.com/kata/58f8a3a27a5c28d92e000144/train/javascript

const firstNonConsecutive = (arr) => {
const arrLen = arr.length
let prev = arr[0]
for (let i = 1; i < arrLen; i += 1) {
const now = arr[i]
if (now - prev !== 1) {
return arr[i]
}
prev = now
}
return null
}

firstNonConsecutive([1, 2, 3, 4, 6, 7, 8]) === 6
firstNonConsecutive([1, 2, 3, 4]) === null