Created
February 1, 2016 14:39
-
-
Save chuck0523/9f9559693438e2d5c227 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 Main(input) { | |
var current_char; | |
var serial = 1; | |
var str = input.replace('\n', '')+' '; | |
var converted_str = ''; | |
current_char = str[0]; | |
for(var i = 1; i < str.length; i += 1) { | |
if(str[i] === current_char) { | |
serial += 1; | |
} else { | |
converted_str += current_char + serial; | |
current_char = str[i]; | |
serial = 1; | |
} | |
} | |
console.log(converted_str); | |
} | |
Main(require("fs").readFileSync("/dev/stdin", "utf8")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment