Pokazuje mi "undefined" przy wpisywaniu "number"

0

Hej,
mam napisany kod, który ma mi pokazywać true albo false zależnie od tego czy w stringu jest ta sama ilość "x" i "o". Wszystko gra ale jak są podane same cyfry to wywala mi "undefined" i nie wiem dlaczego. Może ktoś coś poradzi?

function XO(str) {
    if (typeof(str) === "number") return false;
    str = str.toLowerCase();
    if (str === "") return true
    if (str.indexOf("x") >= 0 && str.indexOf("o") >= 0) {
      const x = str.match(/x/g).length;
      const o = str.match(/o/g).length;
      if (x === o) return true
    } else return false
    
}
0
const XO = str => {
    const count = reg => (String(str).toLowerCase().match(reg) || []).length;
    const xCount = count(/x/g);
    const oCount = count(/o/g);
    return xCount > 0 && xCount === oCount;
}

1 użytkowników online, w tym zalogowanych: 0, gości: 1