-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap_examples.js
40 lines (35 loc) · 981 Bytes
/
map_examples.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
function getBooksTitle(books) {
return myMap(books, getTitle);
}
function myMap(array, func) {
let newArray = [];
array.forEach(element => newArray.push(func(element)));
return newArray;
}
let books = [
{
title: 'JavaScript and JQuery: Interactive Front-End Web Development',
author: 'Jon Ducket',
edition: '1st',
},
{
title: 'Eloquent JavaScript: A Modern Introduction to Programming',
author: 'Haverbeke',
edition: '2nd',
},
{
title: "Learning Web Design: A Beginner's Guide to HTML, CSS, JavaScript, and Web Graphics",
author: 'Jennifer Niederst Robbins',
edition: '4th',
},
];
function getTitle(book) {
return book['title'];
}
console.log(getBooksTitle(books));
// console output
// [
// "JavaScript and JQuery: Interactive Front-End Web Development",
// "Eloquent JavaScript: A Modern Introduction to Programming",
// "Learning Web Design: A Beginner's Guide to HTML, CSS, JavaScript, and Web Graphics"
// ]