We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
You don't need max from B. You need min from B which is basically the first element of B array.
Also you don't need to start from 0, you need to start from the max value from A array which is the last element of A.
And finally you don't need to increment step by just 1. You need to increment by the max value from the A array.
`function getTotalX(a, b) {
// Write your code here
let validNums = 0;
let currNum = a[a.length - 1];
for (let i = currNum; i <= b[0]; i += currNum) {
if (a.every(el => i % el === 0)) {
if (b.every(el => el % i === 0)) { validNums++; }
}
}
return validNums;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Between Two Sets
You are viewing a single comment's thread. Return to all comments →
You don't need max from B. You need min from B which is basically the first element of B array. Also you don't need to start from 0, you need to start from the max value from A array which is the last element of A. And finally you don't need to increment step by just 1. You need to increment by the max value from the A array.
`function getTotalX(a, b) { // Write your code here let validNums = 0; let currNum = a[a.length - 1];
for (let i = currNum; i <= b[0]; i += currNum) { if (a.every(el => i % el === 0)) { if (b.every(el => el % i === 0)) { validNums++; } } } return validNums; }