Skip to content

Commit

Permalink
Create Eva_and_Sara
Browse files Browse the repository at this point in the history
  • Loading branch information
thejensen authored Mar 7, 2017
1 parent d098070 commit bc81181
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions algorithms/March-2017/reduced-string/Eva_and_Sara
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
function processData(input) {
var arr = input.split("");
var new_arr = [];
for (var i = 0; i < arr.length; i++) {
if (i == arr.length -1) {
new_arr.push(arr[i]);
} else if(arr[i] != arr[i+1]){
new_arr.push(arr[i]);
} else {
i++;
}
}
if(new_arr.join("") !== input){
processData(new_arr.join(""))
} else {
console.log(new_arr.length == 0 ? "Empty String" : new_arr.join(""));
}
}

process.stdin.resume();
process.stdin.setEncoding("ascii");
_input = "";
process.stdin.on("data", function (input) {
_input += input;
});

process.stdin.on("end", function () {
processData(_input);
});

0 comments on commit bc81181

Please sign in to comment.