Last active
April 17, 2018 14:22
-
-
Save gracefullight/6afddfe852f5440375d99ef8d423bc35 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function checkSequnceNumbers(target, counterLength= 6){ | |
// under es6 | |
// let sequentialCounter = Array.apply(null, Array(counterLength)).map(Number.prototype.valueOf,0); | |
let sequentialCounter = new Array(counterLength).fill(0); | |
let count = 0; | |
for (let i = 0, len = target.length; i < len; i++) { | |
let subCount = 0; | |
for (let j = 1; j < len; j++) { | |
if (target[j] === (target[i]+1)) { | |
subCount = subCount + 1; | |
} else { | |
continue; | |
} | |
} | |
count = count + subCount; | |
if (subCount === 0) { | |
sequentialCounter[count] = sequentialCounter[count] + 1; | |
count = 0; | |
} | |
} | |
return sequentialCounter; | |
} | |
let target = [1, 2, 3, 5, 6, 7, 8, 10, 11, 13, 16, 17]; | |
console.log(checkSequnceNumbers(target)); | |
// => [1, 2, 1, 1, 0, 0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment