This guide examines how to properly find the full set of potential products in a Ruby collection.
Summary
Build a method that returns all of the divisible items of two integers.
Exercise File
Exercise Description
Implement a method that returns all of the potential products of two integers in Ruby up through a certain range.
Sample Input
1..120000 # range 200 # number 1 73 # number 2
Expected Output
[14600, 29200, 43800, 58400, 73000, 87600, 102200, 116800]
Real World Usage
This exercise will test your knowledge of how to work with the modulus operator and ranges. Additionally, you’ll learn how to return a full collection of selected items.
Solution
Can be found on the solutions branch on github.
mod % num1.zero? && mod % num2.zero?
TypeError:
false can’t be coerced into Fixnum
We need to be sure there are parentheses around each condition to solve this error.
(mod % num1).zero? && (mod % num2).zero?
There is a coding exercise a few days back that gives a similar error.