Write a method named arrayAllFactors that, given an array of Int values greater than 0,
returns whether the values are all factors of one of the values in the array,
which we'll call the greatest multiple.
For example, given the array {4, 2, 8} you would return true,
since 2 and 4
are factors of the greatest multiple 8. Given the array {2, 2, 5} you would return false,
since there is no value that all others are factors of.
You should approach this problem in two steps. First, identify the greatest multiple—the value in the array that you are going to check whether others are factors of. This may sound complicated, but it's straightforward. You do not need to and should not check whether every value is the base! Your solution should not contain a nested loop.
Next, check all the values in the array and look for a counterexample—a value that is not a factor of the base.
The passed array may be null or empty.
In those cases you should return false. Valid arrays will contain
only integers strictly greater than 0.
Stuck? You may find these lessons helpful: