Created
July 20, 2017 21:28
-
-
Save jwalsh/eb183992e5992491082f854dd476ccef 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
| const fetch = require('node-fetch'); | |
| let posts = []; | |
| let postsPromise = fetch('https://jsonplaceholder.typicode.com/posts') | |
| .then(resp => resp.json()) | |
| .then(data => { | |
| posts = data.slice(5,15); | |
| }); | |
| let users = {}; | |
| let usersPromise = fetch('https://jsonplaceholder.typicode.com/users') | |
| .then(resp => resp.json()) | |
| .then(data => { | |
| users = data.reduce((p, c) => { | |
| p[c.id] = c; | |
| return p; | |
| }, {}); | |
| }); | |
| Promise | |
| .all([postsPromise, usersPromise]) | |
| .then(responses => { | |
| // console.log(posts, users); | |
| let table = posts.map(e => { | |
| return { | |
| author: users[e.userId].name, | |
| website: users[e.userId].website, | |
| title: e.title | |
| }; | |
| }); | |
| console.log(table); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment