Created
January 7, 2018 05:16
-
-
Save Johnsalzarulo/da24068be122ef5178a9bbb3364e8ade to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#My anwer for https://www.interviewcake.com/question/ruby/permutation-palindrome | |
class Palindrome | |
def self.test_string(text) | |
characters = text.split(//) | |
odd_char = characters.select {|char| characters.count(char).odd?}.uniq | |
if odd_char.count == 1 or odd_char.count == 0 | |
true | |
else | |
false | |
end | |
end | |
def self.test_all | |
strings = ['civic', 'ivicc', 'civil', 'livci', 'racecar','a but tuba', 'notpalindrome'] | |
strings.each do |string| | |
puts "#{string}: #{Palindrome.test_string(string)}" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment