Skip to content

Instantly share code, notes, and snippets.

@Nasah-Kuma
Created February 4, 2025 08:49
Show Gist options
  • Save Nasah-Kuma/ede843e2f3335a737a6a1599ec0143b3 to your computer and use it in GitHub Desktop.
Save Nasah-Kuma/ede843e2f3335a737a6a1599ec0143b3 to your computer and use it in GitHub Desktop.
function getTotalX(a, b) {
// Write your code here
let lowerBoundInt = a[a.length - 1];
let upperBoundInt = b[0];
let arrayInt = [];
let arrayForFactorsOfA = [];
let arrayWhoseFactorsAreB = [];
let finalArr = [];
if(lowerBoundInt > upperBoundInt) {
return 0;
}
for(let i=lowerBoundInt; i<= upperBoundInt; i++) {
arrayInt.push(i);
}
arrayInt.forEach(item => {
let count = 0
a.forEach((element, i) => {
(item % element === 0) && count++;
(count === a.length) && arrayForFactorsOfA.push(item);
})
});
arrayInt.forEach(item => {
let count = 0
b.forEach((element, i) => {
(element % item === 0) && count++;
(count === b.length) && arrayWhoseFactorsAreB.push(item);
})
});
//finds the items that exist in both arrays
finalArr = arrayWhoseFactorsAreB.filter(item => arrayForFactorsOfA.includes(item))
return finalArr.length;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment