Skip to content

Instantly share code, notes, and snippets.

@skyend
Created May 24, 2018 11:10
Show Gist options
  • Save skyend/976d7ffb8ffa3e4a183c59b25226eeb6 to your computer and use it in GitHub Desktop.
Save skyend/976d7ffb8ffa3e4a183c59b25226eeb6 to your computer and use it in GitHub Desktop.
Chained Characters
var a = "efgaaa123";
var chain = 0;
var chains = [];
var prev = -1, prev2, current;
for(let i= 0; i < a.length; i++ ){
current = a.charCodeAt(i);
if( prev + 1 == current && prev2 + 1 == prev ){
chain ++;
chains.push(String.fromCharCode.apply(null, [prev2, prev, current]))
}
prev2 = prev;
prev = current;
}
console.log('chaing string', chain, chains)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment