-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path01-basic-array.js
More file actions
44 lines (40 loc) · 927 Bytes
/
01-basic-array.js
File metadata and controls
44 lines (40 loc) · 927 Bytes
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
// Subject
var names = [ 'Sarah Smith', 'Adam Scott', 'Eve Livingston' ];
// Pipeline
/**
* Instructions:
* Produce an array of objects with keys firstName, lastName and userName
* from the above array.
*/
var usersPipeline = names.map(function (name) {
/**
* return { firstName: result[0], lastName: result[1] }
*/
})
.map(function (user) {
/**
* return { firstName: "John", lastName: "Doe", userName: "johnDoe" }
*/
});
/**
* Why TWO maps? Good question!
*/
/**
* Want more of a challenge? Use a `reduce()` and create a user object, rather than a collection
* keyed off of the `userName` you just created. E.g.:
*
* {
* sarahSmith: {
* firstName: "Sarah",
* lastName: "Smith",
* userName: "sarahSmith"
* },
* adamScott: {
* firstName: "Adam",
* lastName: "Scott",
* userName: "adamScott"
* }
* // ...
* }
*/
console.log(usersPipeline);