constexsAndOhs=// "π they haunt meβ¦" (https://www.youtube.com/watch?v=0uLI6BnVh6w)(string)=>string.toLowerCase().split("").reduce((count,letter)=>/x/.test(letter)?count+=1:/o/.test(letter)?count-=1:count,0)===0;exsAndOhs("xoxo")// => trueexsAndOhs("like ghosts, they want me")// => falseexsAndOhs("to make them all, they won't let go")// => falseexsAndOhs("ex's and ohs")// => true
TERNARY CHAINS?? Yeah. I'm a loner, Dottie. A rebelβ¦
Now in elixir because hey all the cool kids are using not-Javascript here.
defmoduleExsAndOhsdodeftry_to_get_over_them(string)dostring|>String.downcase|>test(0)# The `Enum` module's for chumps.enddefptest("",count),do:count==0# whole string is traverseddefptest("x"<>string,count),do:# next grapheme is an "x"test(string,count+1)defptest("o"<>string,count),do:# next grapheme is an "o"test(string,count-1)defptest(string,count),do:# String.next_grapheme/1 is a tuple πstring|>String.next_grapheme|>elem(1)|>test(count)end
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.
TERNARY CHAINS?? Yeah. I'm a loner, Dottie. A rebelβ¦
Now in elixir because hey all the cool kids are using not-Javascript here.