Created
December 25, 2022 05:30
-
-
Save thmain/88a0261c589f6c9ec272d01286ddd13c 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
'use strict'; | |
function flattenThreeLevelNestedTree() { | |
var movieLists = [{ | |
name: "Instant Queue", | |
videos: [{ | |
"id": 70111470, | |
"title": "Die Hard", | |
"boxarts": [{ | |
width: 150, | |
height: 200, | |
url: "http://cdn-0.nflximg.com/images/2891/DieHard150.jpg" | |
}, { | |
width: 200, | |
height: 200, | |
url: "http://cdn-0.nflximg.com/images/2891/DieHard200.jpg" | |
}] | |
}, { | |
"id": 654356453, | |
"title": "Bad Boys", | |
"boxarts": [{ | |
width: 200, | |
height: 200, | |
url: "http://cdn-0.nflximg.com/images/2891/BadBoys200.jpg" | |
}, { | |
width: 150, | |
height: 200, | |
url: "http://cdn-0.nflximg.com/images/2891/BadBoys150.jpg" | |
}] | |
}] | |
}, { | |
name: "New Releases", | |
videos: [{ | |
"id": 65432445, | |
"title": "The Chamber", | |
"boxarts": [{ | |
width: 150, | |
height: 200, | |
url: "http://cdn-0.nflximg.com/images/2891/TheChamber150.jpg" | |
}, { | |
width: 200, | |
height: 200, | |
url: "http://cdn-0.nflximg.com/images/2891/TheChamber200.jpg" | |
}] | |
}, { | |
"id": 675465, | |
"title": "Fracture", | |
"boxarts": [{ | |
width: 200, | |
height: 200, | |
url: "http://cdn-0.nflximg.com/images/2891/Fracture200.jpg" | |
}, { | |
width: 150, | |
height: 200, | |
url: "http://cdn-0.nflximg.com/images/2891/Fracture150.jpg" | |
}, { | |
width: 300, | |
height: 200, | |
url: "http://cdn-0.nflximg.com/images/2891/Fracture300.jpg" | |
}] | |
}] | |
}]; | |
// Use one or more map, concatAll, and filter calls to create an array with the following items | |
// [ | |
// {"id": 675465,"title": "Fracture","boxart":"http://cdn-0.nflximg.com/images/2891/Fracture150.jpg" }, | |
// {"id": 65432445,"title": "The Chamber","boxart":"http://cdn-0.nflximg.com/images/2891/TheChamber150.jpg" }, | |
// {"id": 654356453,"title": "Bad Boys","boxart":"http://cdn-0.nflximg.com/images/2891/BadBoys150.jpg" }, | |
// {"id": 70111470,"title": "Die Hard","boxart":"http://cdn-0.nflximg.com/images/2891/DieHard150.jpg" } | |
// ]; | |
return movieLists.map((movie) => { | |
return movie.videos.map((video) => { | |
return video.boxarts.filter((boxart) => { | |
return boxart.width === 150; | |
}).map((item) => { | |
return { | |
"id": video.id, | |
"title": video.title, | |
"boxart": item.url | |
}; | |
}) | |
}).concatAll(); | |
}).concatAll(); | |
} | |
console.log(flattenThreeLevelNestedTree()); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment