Created
January 10, 2017 09:13
-
-
Save danielpetrov/67a12b841897f6dc3d7330b8ace15bfe to your computer and use it in GitHub Desktop.
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
var input = [ | |
{ | |
title: "Batman Begins", | |
year: 2005, | |
cast: [ | |
"Christian Bale", | |
"Michael Caine", | |
"Liam Neeson", | |
"Katie Holmes", | |
"Gary Oldman", | |
"Cillian Murphy" | |
] | |
}, | |
{ | |
title: "The Dark Knight", | |
year: 2008, | |
cast: [ | |
"Christian Bale", | |
"Heath Ledger", | |
"Aaron Eckhart", | |
"Michael Caine", | |
"Maggie Gyllenhal", | |
"Gary Oldman", | |
"Morgan Freeman" | |
] | |
}, | |
{ | |
title: "The Dark Knight Rises", | |
year: 2012, | |
cast: [ | |
"Christian Bale", | |
"Gary Oldman", | |
"Tom Hardy", | |
"Joseph Gordon-Levitt", | |
"Anne Hathaway", | |
"Marion Cotillard", | |
"Morgan Freeman", | |
"Michael Caine" | |
] | |
} | |
]; | |
const flatMap = (data, propName) => { | |
return data.reduce((acc, value) => { | |
value[propName].forEach(star => { | |
if (acc.indexOf(star) === -1) { | |
acc.push(star); | |
} | |
}); | |
return acc; | |
}, []); |
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 data = [[1,2,3], [4,5,6], [7,8,9]] | |
const flattenData = data => data.reduce((acc, value) => acc.concat(value),[] ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment