re: Daily Challenge #29 - Xs and Os VIEW POST

FULL DISCUSSION
 

JavaScript:

const XO = (string) => {
    const chars = string.toLowerCase().replace(/[^xo]/g, '').split('');
    const reducer = (accumulator, char) => char === 'x' ? ++accumulator : --accumulator;

    return chars.reduce(reducer, 0) === 0;
};

or (less readable):

const XO = (string) => {
  return (string.match(/[xo]/gi) || []).reduce((acc, char) => char === 'x' ? ++acc : --acc, 0) === 0;
};
code of conduct - report abuse