Skip to content

Commit 8e4f8ef

Browse files
author
Kyle Maune
committed
added solution for string reduction
1 parent 471712f commit 8e4f8ef

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Medium Difficulty/stringReduction.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// coderbyte solution for string reduction
2+
// splashinn
3+
4+
function StringReduction(str) {
5+
var lastLength;
6+
7+
do {
8+
lastLength = str.length;
9+
str = str.replace(/ab|ba/, "c");
10+
str = str.replace(/bc|cb/, "a");
11+
str = str.replace(/ac|ca/, "b");
12+
}
13+
while (lastLength > str.length)
14+
return str.length;
15+
}

0 commit comments

Comments
 (0)