function XO(str) {
var x = [];
var o = [];
for (var i = 0; i < str.length; i++) {
if (str[i].toLowerCase() === 'x') {
x.push(str[i]);
} else if (str[i].toLowerCase() === 'o') {
o.push(str[i]);
}
}
if (x.length == o.length) {
return true;
} else {
return false;
}
}
console.log(XO('xo'));
console.log(XO('xxo'));
console.log(XO('xoX'));
console.log(XO('xoOX'));
No comments:
Post a Comment