forked from Automedon/CodeWars-6-kyu-Soluitions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCoding Meetup #16 - Higher-Order Functions Series - Ask for missing details.js
48 lines (37 loc) · 2.04 KB
/
Coding Meetup #16 - Higher-Order Functions Series - Ask for missing details.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
48
/*
Description:
You will be given an array of objects representing data about developers who have signed up to attend the next coding meetup that you are organising.
Given the following input array:
var list1 = [
{ firstName: null, lastName: 'I.', country: 'Argentina', continent: 'Americas', age: 35, language: 'Java' },
{ firstName: 'Lukas', lastName: 'X.', country: 'Croatia', continent: 'Europe', age: 35, language: null },
{ firstName: 'Madison', lastName: 'U.', country: 'United States', continent: 'Americas', age: 32, language: 'Ruby' }
];
write a function that
1) adds the question property to each object in the input array where the developer has not provided the relevant details (marked with a null value). The value of the question property should be the following string:
Hi, could you please provide your <property name>.
2) and returns only the developers with missing details:
[
{ firstName: null, lastName: 'I.', country: 'Argentina', continent: 'Americas', age: 35, language: 'Java',
question: 'Hi, could you please provide your firstName.' },
{ firstName: 'Lukas', lastName: 'X.', country: 'Croatia', continent: 'Europe', age: 35, language: null,
question: 'Hi, could you please provide your language.' }
]
Notes:
At most only one of the values will be null.
Preserve the order of the original list.
Return an empty array [] if there is no developer with missing details.
The input array will always be valid and formatted as in the example above.
This kata is part of the Coding Meetup series which includes a number of short and easy to follow katas which have been designed to allow mastering the use of higher-order functions. In JavaScript this includes methods like: forEach, filter, map, reduce, some, every, find, findIndex. Other approaches to solving the katas are of course possible.
*/
function askForMissingDetails(list) {
let arr = [];
list.map(list=>{
for (let i in list){
if (list[i]===null){
list={...list,question:`Hi, could you please provide your ${i}.`}
arr.push(list)
}
}})
return arr
}