-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathisogram_detector.rb
More file actions
35 lines (31 loc) · 812 Bytes
/
isogram_detector.rb
File metadata and controls
35 lines (31 loc) · 812 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
def is_isogram(word)
# uniq removes duplicate characters in the word
# Then, checks if the length of the original word is equal to the length of the set
word.downcase.chars.uniq.length == word.length
end
def main
word = gets.chomp
puts is_isogram(word)
end
if __FILE__ == $0
main
end
# ALTERNATIVE METHOD:
# def is_isogram(word)
# # Create a new array to store each letter in the word
# letters = []
#
# # Loop through each character in the word
# word.each_char do |char|
# # If the letter is already in the array, the word is not an isogram
# if letters.include?(char)
# return false
# end
#
# # Otherwise, add the letter to the array
# letters << char
# end
#
# # If the loop completes without returning false, the word is an isogram
# return true
# end