8000 add titles solution · cotrones/javascript-exercises@01aace2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 01aace2

Browse files
committed
add titles solution
1 parent ffa0027 commit 01aace2

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

getTheTitles/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# GET THE TITLES!
2+
3+
You are given an array of objects that represent books with an author and a title that looks like this:
4+
5+
```javascript
6+
const books = [
7+
{
8+
title: 'Book',
9+
author: 'Name'
10+
},
11+
{
12+
title: 'Book2',
13+
author: 'Name2'
14+
}
15+
]
16+
```
17+
18+
your job is to write a function that takes the array and returns an array of titles:
19+
20+
```javascript
21+
getTheTitles(books) // ['Book','Book2']
22+
```
23+
24+
## Hints
25+
26+
- You should use a built-in javascript method to do most of the work for you!
27+
<Paste>

getTheTitles/getTheTitles.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
var getTheTitles = function(array) {
2+
return array.map(book => book.title)
3+
}
4+
5+
module.exports = getTheTitles

getTheTitles/getTheTitles.spec.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
let getTheTitles = require('./getTheTitles')
2+
3+
describe('getTheTitles', function() {
4+
const books = [
5+
{
6+
title: 'Book',
7+
author: 'Name'
8+
},
9+
{
10+
title: 'Book2',
11+
author: 'Name2'
12+
}
13+
]
14+
15+
it('gets titles', function() {
16+
expect(getTheTitles(books)).toEqual(['Book','Book2']);
17+
});
18+
19+
});

0 commit comments

Comments
 (0)
0