Have the function ExOh(str) take the str parameter being passed and return the string true if there is an equal number of x's and o's, otherwise return the string false.Only these two letters will be entered in the string, no punctuation or numbers.
For example: if str is "xooxxxxooxo" then the output should return false because there are 6 x's and 5 o's.
Ex Oh Coderbyte Solution In Java
Ex Oh Coderbyte Solution In Python
Ex Oh Coderbyte Solution In JavaScript
Using the JavaScript language, have the function ExOh(str) take the str parameter being passed and return the string true if there is an equal number of x's and o's, otherwise return the string false. Only these two letters will be entered in the string, no punctuation or numbers. For example: if str is "xooxxxxooxo" then the output should return false because there are 6 x's and 5 o's.
Explanation
My solution accounts for the one outlier which is when the length of the string is not even. Since the count of Xs and Os have to be equal then the only way for this to happen is if the length of the string is an even number. I am going to loop through the string and count every X. Then I am going to compare this count to half the length of the string. If they are equal then you have equal number of Xs and Os.
Disclaimer: The above Problem is generated by Coderbyte but the Solution is provided by ShouterFolk.