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
}