The problem is best explained by the comments in my code.
// Find all commonNums divisible by arr && sequential that produce a whole number quotient.
// commonNums [ 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75]
// arr [1,5]
// sequential [ 2, 3, 4 ]
for (var n = 0; n < commonNums.length; n++) {
for (var o = 0; o < sequential.length; o++) {
for (var p = 0; p < arr.length; p++) {
if (commonNums[n] % arr[p] === 0 && commonNums[n] % sequential[o] === 0) {
console.log(commonNums[n]);
}}}
}
Since the arrays are of different length, simply iterating through with one loop of length commonNums.length produced undefined values. My solution was to use 3 loops, one for each array.
If common nums divided by arr has no remainder, and if common nums divided by sequential has no remainder, then return that number. For arr [1,5] the first number returned should be 60.
Why does this solution fail?
10 % 1 == 0and10 % 2 == 0