Skip to content

Latest commit

 

History

History
27 lines (22 loc) · 701 Bytes

File metadata and controls

27 lines (22 loc) · 701 Bytes

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.

Screen Shot 2022-07-15 at 23 26 59

function XO(str) {
  let x = 0;
  let o = 0;
  for (let i = 0; i < str.length; i++) {
    if (str[i].toLowerCase() === "x") {
      x++;
    } else if (str[i].toLowerCase() === "o") {
      o++;
    }
  }
  return x === o;
}

Short answer

function XO(str) {
    return str.toLowerCase().split('x').length === str.toLowerCase().split('o').length;
}