Skip to content

Commit b8f2465

Browse files
authored
Update Ex Oh
1 parent 2972e34 commit b8f2465

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

Ex Oh

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,21 @@
2424
* 4) Else return false *
2525
* *
2626
***************************************************************************************/
27-
function ExOh(str) {
27+
function ExOh(str) {
28+
let countX = 0;
29+
let countO = 0;
2830

29-
if (str.length % 2 === 1) {
30-
return false;
31-
}
32-
else {
33-
var tot = 0;
34-
for (var i = 0; i < str.length; i++) {
35-
if (str[i] === "x") {
36-
tot++;
37-
}
31+
for (let char of str) {
32+
if (char === 'x') {
33+
countX++;
34+
} else if (char === 'o') {
35+
countO++;
3836
}
39-
40-
if (tot === (str.length / 2)) {
41-
return true;
42-
}
43-
else {
44-
return false;
45-
}
46-
4737
}
48-
38+
39+
return countX === countO;
4940
}
41+
42+
// Test cases
43+
console.log(ExOh("xooxxxxooxo")); // Expected output: false
44+
console.log(ExOh("xoxo")); // Expected output: true

0 commit comments

Comments
 (0)