Skip to content

Commit a0930ea

Browse files
committed
14 - Ex Oh.js
1 parent c86bd4f commit a0930ea

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

14 - Ex Oh.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Step By Step
2+
function ExOh (str) {
3+
// First, we declare two variables:
4+
// One which remove all characters in the string that aren't x's...
5+
var strX = str.replace(/[^x]/g, '');
6+
7+
// ...and and the second which removes all characters that aren't o's
8+
var strO = str.replace(/[^o]/g, '');
9+
10+
// Next, we get the length of each of these new variables to determine how many x's and o's are in the string...
11+
var xNumber = strX.length;
12+
var oNumber = strO.length;
13+
14+
// ...and return the truth value of comparing the two.
15+
return xNumber === oNumber;
16+
}
17+
18+
// No Comments
19+
function ExOh (str) {
20+
return str.replace(/[^x]/g, '').length === str.replace(/[^o]/g, '').length;
21+
}

0 commit comments

Comments
 (0)