def isogram?(string)
letters = string.downcase.scan(/[a-z]/)
letters.uniq.length == letters.length
end
- Suggest using
scan
rather thangsub
as it removes the need to break the string into chars.
- Comparing lengths (
letters.uniq.length == letters.length
) is marginally quicker than comparing letters (letters.uniq == letters
) but its more code. Which is better?
- 2021 Nov - Markdown adjustment to style guide (sentences and links)