Created
October 21, 2019 09:46
-
-
Save daubattu/5cdc2f5d332cfa5ddbf5b5c187499981 to your computer and use it in GitHub Desktop.
[Hackerrank] Solution of Between Two Sets in JavaScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice solution and easy to understand. Comments helped.