Created
May 24, 2018 11:10
-
-
Save skyend/976d7ffb8ffa3e4a183c59b25226eeb6 to your computer and use it in GitHub Desktop.
Chained Characters
This file contains hidden or 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
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