Files
medusa-store/packages/admin-ui/ui/src/utils/get-combinations.js
2023-03-03 10:09:16 +01:00

27 lines
543 B
JavaScript

export const getCombinations = (options) => {
if (options.length === 0) {
return []
}
if (options.length === 1) {
const values = options.shift().values
if (values.length > 0) {
return values.map((v) => [v])
}
return [""]
}
const combinations = []
const theseValues = options.shift().values
const lowerCombinations = getCombinations(options)
for (const v of theseValues) {
for (const second of lowerCombinations) {
combinations.push([v, second].flat())
}
}
return combinations
}