Can you check to see if a string has the same amount of 'x's and 'o's?
Examples input/output:
XO("ooxx") => true
XO("xooxx") => false
XO("ooxXm") => true
XO("zpzpzpp") => true // when no 'x' and 'o' is present should return true
XO("zzoo") => false
Note: The method must return a boolean and be case insensitive. The string can contain any character
This challenge comes from user joh_pot. Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!
Want to propose a challenge for a future post? Email yo+challenge@dev.to with your suggestions!
Latest comments (56)
Rust
Rust Playground
GitHub Gist
Python:
My solution in js
Haskell:
Elixir:
I broke out the work a little more, I tried to be a tad clever and utilize switch but wasn't able to get it to work quite the way I wanted.
Hopefully, the slightly more vanilla JS will be useful in some way.
I was removing elements with plans of creating two for loops going in opposite directions to speed up the process... but that was for fun and it lost interest in it.
This is my solution, I'm still learning javascript so nothing fancy
Javascript with no loops:
Python goes there :
[V2] - One liner :
Some comments may only be visible to logged-in visitors. Sign in to view all comments.