Created
March 18, 2019 22:14
-
-
Save matthew-gerstman/31a1fc7ad9ef71acd0d9ed5ee3503e90 to your computer and use it in GitHub Desktop.
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 flatMap(list, func) { | |
return list.reduce((acc, item) => { | |
const mappedItem = func(item); | |
if (Array.isArray(mappedItem)) { | |
acc = acc.concat(mappedItem); | |
} else { | |
acc.push(mappedItem); | |
} | |
return acc; | |
}, []); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment