-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo7.js
51 lines (39 loc) · 1.07 KB
/
demo7.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
Check to see if a string has the same amount of 'x's and 'o's. The method must return a boolean and be case insensitive. The string can contains any char.
Examples input/output:
XO("ooxx") => true
XO("xooxx") => false
XO("ooxXm") => true
XO("zpzpzpp") => true // when no 'x' and 'o' is present should return true
XO("zzoo") => false
function XO(str) {
//code here
str = str.toLowerCase();
var a = 0;
var c = 0;
for(var i in str){
if(str[i]=='x'){
a++
}
if(str[i]=='o'){
c++
}
}
if(a==c){return true;}else{return false;}
}
function XO(str) {
let x = str.match(/x/gi);
let o = str.match(/o/gi);
return (x && x.length) === (o && o.length);
}
const XO = str => {
str = str.toLowerCase().split('');
return str.filter(x => x === 'x').length === str.filter(x => x === 'o').length;
}
function XO(str) {
var a = str.replace(/x/gi, ''),
b = str.replace(/o/gi, '');
return a.length === b.length;
}
function XO(str) {
return str.replace(/o/ig, '').length == str.replace(/x/ig, '').length
}