Created
May 10, 2017 14:25
-
-
Save electerious/961fbc62cc396bc086950b3ca661d9d1 to your computer and use it in GitHub Desktop.
Duplicate array items based on an array
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
const duplicate = (arr, duplications) => arr.reduce((acc, val, i) => { | |
const duplication = duplications[i] | |
for (let i = 0; i<duplication; i++) acc.push(val) | |
return acc | |
}, []) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example: