all
Your if can become:
if (2..20).all? {|d| x % d == 0}
To avoid repetition.
all
returns at the first false so this should be as fast as yours.
Caridorc
- 28k
- 7
- 54
- 137
default
Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Visit Stack Exchangeall
Your if can become:
if (2..20).all? {|d| x % d == 0}
To avoid repetition.
all
returns at the first false so this should be as fast as yours.