add titles solution
This commit is contained in:
parent
ffa00275cc
commit
01aace24b1
3 changed files with 51 additions and 0 deletions
27
getTheTitles/README.md
Normal file
27
getTheTitles/README.md
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
# GET THE TITLES!
|
||||||
|
|
||||||
|
You are given an array of objects that represent books with an author and a title that looks like this:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const books = [
|
||||||
|
{
|
||||||
|
title: 'Book',
|
||||||
|
author: 'Name'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Book2',
|
||||||
|
author: 'Name2'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
your job is to write a function that takes the array and returns an array of titles:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
getTheTitles(books) // ['Book','Book2']
|
||||||
|
```
|
||||||
|
|
||||||
|
## Hints
|
||||||
|
|
||||||
|
- You should use a built-in javascript method to do most of the work for you!
|
||||||
|
<Paste>
|
5
getTheTitles/getTheTitles.js
Normal file
5
getTheTitles/getTheTitles.js
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
var getTheTitles = function(array) {
|
||||||
|
return array.map(book => book.title)
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = getTheTitles
|
19
getTheTitles/getTheTitles.spec.js
Normal file
19
getTheTitles/getTheTitles.spec.js
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
let getTheTitles = require('./getTheTitles')
|
||||||
|
|
||||||
|
describe('getTheTitles', function() {
|
||||||
|
const books = [
|
||||||
|
{
|
||||||
|
title: 'Book',
|
||||||
|
author: 'Name'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Book2',
|
||||||
|
author: 'Name2'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
it('gets titles', function() {
|
||||||
|
expect(getTheTitles(books)).toEqual(['Book','Book2']);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
Loading…
Reference in a new issue