Last active
August 6, 2021 15:32
-
-
Save stoneboyindc/417b7cfdf8685b4d1ddef5dee6f44f78 to your computer and use it in GitHub Desktop.
getBooksPossessedByAccount()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getBooksPossessedByAccount(account, books, authors) { | |
//Initialze a return array | |
let booksPossessed=[]; | |
//check for the account id in the borrows arrays | |
books.forEach(book => { | |
let borrowArray = book.borrows; | |
if (borrowArray.find(borrow => borrow.id === account.id && borrow.returned === false)) { | |
booksPossessed.push(book); | |
} | |
}) | |
booksPossessed.forEach(book=>{ | |
let author = authors.find(person => person.id === book.authorId); | |
book['author'] = author; | |
}) | |
console.log(booksPossessed); | |
return booksPossessed; | |
} |
Author
stoneboyindc
commented
Aug 6, 2021
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment