-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask1.js
47 lines (34 loc) · 1.28 KB
/
task1.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
Fetch users from GitHub
Create an async function getUsers(names), that gets an array of GitHub logins, fetches the users from GitHub and returns an array of GitHub users.
The GitHub url with user information for the given USERNAME is: https://api.github.com/users/USERNAME.
There’s a test example in the sandbox.
Important details:
There should be one fetch request per user.
Requests shouldn’t wait for each other. So that the data arrives as soon as possible.
If any request fails, or if there’s no such user, the function should return null in the resulting array.
*/
import fetch from "node-fetch";//Only needed if the node version is less than 18
//let gitnames = ['dicksonchellakon', 'philipplackner']
let getGitDetails = async (username) => {
let gitResponse = await fetch('https://api.github.com/users/'+ username)
if (!gitResponse.ok) return null
return await gitResponse.json()
}
/*
//Loop over the gitnames
gitnames.forEach(gitusername => {
console.log(gitusername)
getGitDetails(gitusername)
.then(gitdetails => {
console.log(gitdetails)
})
});*/
Promise.all([
getGitDetails('dicksonchellakon'),
getGitDetails('philipplackner'),
getGitDetails('mbostock'),
getGitDetails('wronguser1')
]).then(responses =>{
console.log(responses)
});