To fix the program and make it correctly identify 'six-year-old' and 'emily jung schwartzkopf' as isograms, you can modify the isogram? method in the following way:
main.rb202 chars5 linesExplanation:
word is downcased using downcase method to make it case-insensitive.gsub(/\d+/, '') method is used to remove any digits from the word. This is done using a regular expression with \d+ matching one or more digits.match method with the regex /(.).*\1/i to check if any character in the processed word is repeated. If a match is found (i.e., the method returns a non-nil value), then the word is not an isogram and we return false (negated with !). Otherwise, the word is an isogram and we return true.Now, you can test the method as follows:
main.rb101 chars3 lines
Both 'six-year-old' and 'emily jung schwartzkopf' will be correctly identified as isograms.
Note: Since Ruby methods conventionally use snake_case for naming, it is generally recommended to follow this convention for better code readability.
gistlibby LogSnag