Skip to content

Instantly share code, notes, and snippets.

@stoneboyindc
Created March 9, 2021 18:28
Show Gist options
  • Save stoneboyindc/5ccc9f7eb33ed960441201c0c2c0ef70 to your computer and use it in GitHub Desktop.
Save stoneboyindc/5ccc9f7eb33ed960441201c0c2c0ef70 to your computer and use it in GitHub Desktop.
// should return all of the books taken out by an account with the author embedded
function getBooksPossessedByAccount(account, books, authors) {
let books_taken = [];
books.forEach(book=>{
if (book.borrows.find(item=>item.id === account.id && !item.returned)) {
books_taken.push(book);
}
})
console.log(books_taken);
books_taken.forEach(book=>{
let anAuthor = authors.find(person => person.id === book.authorId);
book['author'] = anAuthor;
})
console.log(books_taken);
return books_taken;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment