Skip to content

Instantly share code, notes, and snippets.

@chuck0523
Created February 1, 2016 14:39
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 chuck0523/9f9559693438e2d5c227 to your computer and use it in GitHub Desktop.
Save chuck0523/9f9559693438e2d5c227 to your computer and use it in GitHub Desktop.
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