Tell us what’s happening:
When I tried the function which I created so far, it worked correct as far as arr[1] is less than 13. However, when I made arr[0] equal to 1 and arr[1] equal to 13, the output was incorrect, and what is very strange was that every time when I refreshed it, it came up a different result. Just can’t figure out the reason. NEED HELP thanks…
Your code so far
function smallestCommons(arr) {
var fullArr = [];
if(arr[0] > arr[1]) {
arr.reverse();
}
for(let i = arr[0]; i <= arr[1]; i++) {
fullArr.push(i);
}
var cm = 1;
while(fullArr.map(a => cm % a).reduce((a, b) => a + b) !== 0) {
cm++;
}
return cm;
}
console.log(smallestCommons([1, 17]));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36
.
Link to the challenge: