-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrings-arrays-objects-functions-promises.js
More file actions
93 lines (82 loc) · 2.28 KB
/
strings-arrays-objects-functions-promises.js
File metadata and controls
93 lines (82 loc) · 2.28 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// TASK 1 (5 mins)
// Job offers management system
const jobOffers = [
{
id: 1,
title: "Frontend Developer",
location: "Texas, USA",
salary: "100000",
skills: ["TypeScript", "React", "CSS"],
},
{
id: 2,
title: "Full Stack Engineer",
location: "London, UK",
salary: "80000",
skills: ["JavaScript", "Node.js", "Express"],
},
{
id: 3,
title: "React Engineer",
location: "Sidney, Australia",
salary: "90000",
skills: ["JavaScript", "React", "Redux"],
},
{
id: 4,
title: "Next.js Developer",
location: "Berlin, Germany",
salary: "110000",
skills: ["JavaScript", "Next.js", "TypeScript"],
},
{
id: 5,
title: "Full Stack Engineer (TypeScript, AWS)",
location: "Paris, France",
salary: "120000",
skills: ["TypeScript", "AWS", "Node.js"],
},
];
// Return an array of job titles that require React skills
function findJobsBySkill(jobsData, skill) {
// Your code here
return 'TODO'
}
console.log(findJobsBySkill(jobOffers, 'React'))
// => ['Frontend Developer', 'React Engineer']
// TASK
// Get data for Job Offers list page: request ob Offers and User Profile
// Add type
// jobOffers can have different structure, use Generics
const createApi = (data1) => [
new Promise((resolve) => {
setTimeout(() => {
resolve(data1);
}, 30);
}),
new Promise((resolve) => {
setTimeout(() => {
resolve({
userId: 123,
name: "John Doe",
email: "[email protected]"
});
}, 50);
})
];
// Fetch job offers and user profile data
// Add type
async function fetchJobOffersAndUserProfile(api) {
// Q: How to fetch data from both promises in parallel?
// Q: What to do if one of the promises fails?
// Q: What if we want to return both success and fail results in a single object?
// Q: How to handle errors in async functions?
return 'TODO';
}
const result = fetchJobOffersAndUserProfile(createApi(jobOffers));
// Example usage
// log the result of the function
console.log(result);
// Q: How to get this data from a /job-offers endpoint? using fetch API
// Q: Explain REST principles and how they apply to this endpoint (CRUD operations, filtering, sorting, pagination).
// Q: What other interactions could be implemented with this endpoint (graphQL)?