Last active
August 28, 2020 05:40
-
-
Save msr1k/7b6b86c4272c276660951bc8e33cff06 to your computer and use it in GitHub Desktop.
Get product result of the given arrays (JavaScript)
This file contains 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
const a = [ 1, 2, 3, 4 ]; | |
const b = [ 5, 6, 7 ]; | |
const c = [ 8, 9 ]; | |
const d = { a, b, c } | |
function combinations(aryOfAry) { | |
const combination = (a1, a2) => { | |
let a = [] | |
a1.forEach((v1) => { | |
a2.forEach((v2) => { | |
let t = v1.slice(); | |
t.push(v2); | |
a.push(t); | |
}); | |
}); | |
return a; | |
} | |
let base = [[]]; | |
aryOfAry.forEach((v) => { | |
base = combination(base, v); | |
}); | |
return base; | |
} | |
console.log(combinations(Object.values(d))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment