Check if a string has the same amount of 'x' and 'o'. The method must return a Boolean value and must not be case-sensitive. The string can contain any char.
For further actions, you may consider blocking this person and/or reporting abuse
Check if a string has the same amount of 'x' and 'o'. The method must return a Boolean value and must not be case-sensitive. The string can contain any char.
For further actions, you may consider blocking this person and/or reporting abuse
Latest comments (12)
A simple solution with Rust.
Rust Solution.
Time for a Go kata you say?
play.golang.org/p/n8q9BYrsW4a
Ruby Solution!
Python solution -
Thank you @Pierre for pointing out the error.
Hey @ganeshtata !
I think you missed an uppercase in your
elif:)instead of
To dig a little deeper, I suggest you to see some very useful string methods in Python !
Thank you for that! I had not noticed it. Yes, there are some awesome string methods in Python, but I didn't use any of them here because I wanted to finish the count(s) in one pass of the string. Doing a
.lower()and then counting might involve two passes of the same string.I suggested it to reduce your conditions, lowering the string before checking would have allowed you to only check for
oandxfor example. This way you would have one pass on the string and a more concise condition :)Do you mean lowering the string before the loop or lowering the character in the loop before checking whether it is an 'x' or 'o'?
.lower()on the character.Oh right, nevermind !
Python to the rescue !
output
In Haskell, with what I thought was kind of a neat method:
As a javascript one-liner: