Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Steven Vallarsa
Steven Vallarsa
10,842 Points

I came up with this solution and generated the same result

I solved this on my own and came up with this solution that generated the same result. I reduced the array into an array of objects before mapping the book titles into a new array.

const results = users
    .reduce((arr, item) => [...arr, ...item.favoriteBooks], [])
    .map(arr => arr.title);

Joel's solution is

const books = users
  .map(item => item.favoriteBooks.map(book => book.title))
  .reduce((arr, item) => [...arr, ...item]);

Is one inherently better than the other?

1 Answer

Good solution.

They are both similar so I wouldnt say one is better