Created
September 30, 2016 16:33
-
-
Save harpreetkhalsagtbit/72b875a26a61a6037995c89702aca3a4 to your computer and use it in GitHub Desktop.
count consecutive char freq
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 k = "aaahhrrrvfuuhh".split("") | |
var ref = k[0] | |
var newStr = '' | |
while(k.length) { | |
for(var i=0;i<k.length;i++) { | |
if(k[i] != ref) { | |
console.log(k[i] , ref, i) | |
k = k.splice(i,k.length - 1) | |
if(i > 1) { | |
newStr += ref + i | |
} else { | |
newStr += ref | |
} | |
break; | |
} else { | |
console.log("ELSE") | |
} | |
} | |
ref = k[0] | |
console.log(k, k.length, k[i], ref) | |
if(!k[i]) { | |
newStr += ref + k.length | |
k = []; | |
break; | |
} | |
} | |
console.log(newStr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
output
"a3h2r3vfu2h2"