Exercismの問題を解いた。
問題
Determine if a sentence is a pangram. A pangram (Greek: παν γράμμα, pan gramma, "every letter") is a sentence using every letter of the alphabet at least once. The best known English pangram is:
The quick brown fox jumps over the lazy dog.
The alphabet used consists of ASCII letters a to z, inclusive, and is case insensitive. Input will not contain non-ASCII symbols.
問題の要約:
- ある文章がパングラムかどうか判定せよ
- パングラムとは、すべてのアルファベットが最低でも1回は使われている文章のことである
- 例:「The quick brown fox jumps over the lazy dog」
解答
class Pangram ALPHABET = ('a'..'z') def self.pangram?(sentence) ALPHABET.all? { |x| sentence.downcase.chars.include?(x) } end end
all?
とinclude?
で似たようなロジックに応用できそう。