Skip to content

Instantly share code, notes, and snippets.

@gracefullight
Last active April 17, 2018 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gracefullight/6afddfe852f5440375d99ef8d423bc35 to your computer and use it in GitHub Desktop.
Save gracefullight/6afddfe852f5440375d99ef8d423bc35 to your computer and use it in GitHub Desktop.
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