functionXO(str){letstr_arr=str.toLowerCase().replace(/[^xo]/g,'').split('')//Convert String into an Array to allow using Array.sort().sort();//All of the o's will be placed before the x's thanks to Array.sort()//Add 1 to account for 0-indexing and to turn -1 into 0 when there are no o'sletoCount=str_arr.lastIndexOf('o')+1;letxCount=str_arr.length-oCount;return!(xCount-oCount);}//Run the test casesconsttestCases=["ooxx","xooxx","ooxXm","zpzpzpp","zzoo"];for(stroftestCases){letresult=XO(str);console.log(`"${str}" => ${result}`);}
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Javascript with no loops: