Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.


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