Skip to content

Commit 3f11705

Browse files
author
Kyle Maune
committed
added second solution for string reduction
1 parent 8e4f8ef commit 3f11705

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

Medium Difficulty/stringReduction2.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// coderbyte solution for string reduction
2+
// splashinn
3+
4+
function reduce(str){
5+
str = str.replace(/ab/, "c")
6+
.replace(/ba/, "c")
7+
.replace(/ac/, "b")
8+
.replace(/ca/, "b")
9+
.replace(/bc/, "a")
10+
.replace(/cb/, "a");
11+
return str;
12+
}
13+
14+
function irreducible(str) {
15+
var str = str.split("");
16+
for (var i = 1; i < str.length; i++) {
17+
if (str[i] != str[i-1]) return false;
18+
}
19+
return true;
20+
}
21+
22+
function StringReduction(str) {
23+
do {
24+
str = reduce(str);
25+
} while (str != reduce(str));
26+
27+
return str.length;
28+
29+
}

0 commit comments

Comments
 (0)