알고리즘 78 - Exes and Ohs

tamagoyakii·2021년 11월 4일
0

알고리즘

목록 보기
78/89

Q.

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

A)

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

0개의 댓글