-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathscript.js
54 lines (46 loc) · 921 Bytes
/
script.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
49
50
51
52
53
54
function convert (data) {
// Your code here
// #1
//using for:
// var result = []
// for (var i = 0; i<data.length; i++){
// var biodata = {
// id: data[i][0],
// firstName: data[i][1],
// lastName: data[i][2],
// email: data[i][3]
// }
// result.push(biodata)
// }
// return result
//#2
//using .map();
return data.map( function (x){
var result = []
var biodata = {
id: x[0],
firstName: x[1],
lastName: x[2],
email: x[3]
}
return biodata
}
)
}
// TEST CASES
console.log(convert([
[1, 'Dimitri', 'Wahyudiputra', '[email protected]'],
[2, 'Sergei', 'Dragunov', '[email protected]']
]));
/*
[ { id: 1,
firstName: 'Dimitri',
lastName: 'Wahyudiputra',
email: '[email protected]' },
{ id: 2,
firstName: 'Sergei',
lastName: 'Dragunov',
email: '[email protected]' } ]
*/
console.log(convert([]));
// []