Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save daubattu/5cdc2f5d332cfa5ddbf5b5c187499981 to your computer and use it in GitHub Desktop.
Save daubattu/5cdc2f5d332cfa5ddbf5b5c187499981 to your computer and use it in GitHub Desktop.
[Hackerrank] Solution of Between Two Sets in JavaScript
function getTotalX(a, b) {
// Write your code here
let result = 0;
let index = 1;
let cloneA = a.splice(1, a.length); // clone new array of a but not a[0]
while(a[0] * index <= b[0]) {
if(
cloneA.every(item => (a[0] * index) % item === 0)
&&
b.every(item => item % (a[0] * index) === 0)
) {
result++;
}
index++;
}
return result;
}
@ChanchalS7
Copy link

I can explain it easily.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment