DEV Community

Discussion on: Daily Challenge #29 - Xs and Os

Collapse
 
mohamedelidrissi_98 profile image
Mohamed ELIDRISSI

This is my solution, I'm still learning javascript so nothing fancy

function XO(string) {
  const strArr = string.toLowerCase().split('');
  let os = 0, xs = 0;
  strArr.forEach(word => {
    switch (word) {
      case 'o': 
        os++;
        break;
      case 'x': 
        xs++;
        break;
    }
  });
  return os === xs;
}