-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExesandOhs.js
More file actions
32 lines (26 loc) · 803 Bytes
/
Copy pathExesandOhs.js
File metadata and controls
32 lines (26 loc) · 803 Bytes
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
// 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 contain 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
let strLower = str.toLowerCase()
let counterX = 0;
let counterO = 0;
for(let i = 0; i < strLower.length; i++){
if(strLower[i] === 'x'){
counterX++
} else if(strLower[i] === 'o'){
counterO++
}
}
return counterX === counterO
}
//refactor
const XO = str => {
str = str.toLowerCase().split('');
return str.filter(x => x === 'x').length === str.filter(x => x === 'o').length;
}