DEV Community

Discussion on: Daily Challenge #29 - Xs and Os

Collapse
 
bsides profile image
Rafael Pereira

Javascript (pretty readable):

const makeArrayOfGivenChar = (text, givenChar) => text.split('').filter(c => c.toLowerCase() === givenChar.toLowerCase())

function XO(str) {
  const x = makeArrayOfGivenChar(str, 'x')
  const o = makeArrayOfGivenChar(str, 'o')
  return x.length === o.length
}
Collapse
 
jacobmgevans profile image
Jacob Evans

Well done! I like a one-liner and clever answers as much as the next person HOWEVER I also love seeing elegant, more readable, and even sometimes simplified (broken down more step by step) solutions!

Awesome job!

Collapse
 
bsides profile image
Rafael Pereira

Thank you Jacob! I have the same opinion! 👍