Created
May 7, 2019 16:59
-
-
Save PavelJurasek/48123844df790c5227d33bb32b05738e to your computer and use it in GitHub Desktop.
Create variants of all attributes
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 attrs = [ | |
['r', 'g', 'b'], | |
['l', 'm', 's'], | |
['cyan', 'magenta'], | |
['ano', 'ne'], | |
]; | |
let variants = []; | |
function createVariants(attrsOfCurrentVariant, providedAttrs) { | |
const thisAttr = providedAttrs.shift(); | |
const length = thisAttr.length; | |
for (let i = 0; i < length; i++) { | |
const copy = [...attrsOfCurrentVariant]; | |
copy.push(thisAttr[i]); | |
if (providedAttrs.length > 0) { | |
createVariants(copy, [...providedAttrs]); | |
} else { | |
variants.push(copy); | |
} | |
} | |
} | |
createVariants([], attrs); | |
console.log(variants); | |
console.log(variants.length); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment