From 01aace24b1c3cd72e321851413c2022aa39fe082 Mon Sep 17 00:00:00 2001 From: Cody Loyd Date: Thu, 11 Apr 2019 12:14:20 -0500 Subject: [PATCH] add titles solution --- getTheTitles/README.md | 27 +++++++++++++++++++++++++++ getTheTitles/getTheTitles.js | 5 +++++ getTheTitles/getTheTitles.spec.js | 19 +++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 getTheTitles/README.md create mode 100644 getTheTitles/getTheTitles.js create mode 100644 getTheTitles/getTheTitles.spec.js diff --git a/getTheTitles/README.md b/getTheTitles/README.md new file mode 100644 index 0000000..a44b12f --- /dev/null +++ b/getTheTitles/README.md @@ -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! + diff --git a/getTheTitles/getTheTitles.js b/getTheTitles/getTheTitles.js new file mode 100644 index 0000000..d932e81 --- /dev/null +++ b/getTheTitles/getTheTitles.js @@ -0,0 +1,5 @@ +var getTheTitles = function(array) { + return array.map(book => book.title) +} + +module.exports = getTheTitles diff --git a/getTheTitles/getTheTitles.spec.js b/getTheTitles/getTheTitles.spec.js new file mode 100644 index 0000000..5bd65f9 --- /dev/null +++ b/getTheTitles/getTheTitles.spec.js @@ -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']); + }); + +});