Account Object Example in the Accounts Array:
const accounts = [
{
id: "5f446f2ecfaf0310387c9603",
picture: "https://api.adorable.io/avatars/75/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0e6b7d7a666b7c"/>[email protected]</a>",
age: 25,
name: {
first: "Esther",
last: "Tucker",
},
company: "ZILLACON",
email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="365345425e5344184/>[email protected]</a>",
registered: "Thursday, May 28, 2015 2:51 PM",
},
Book Object Example in the Books Array:
const books = [
{
id: "5f447132d487bd81da01e25e",
title: "sit eiusmod occaecat eu magna",
genre: "Science",
authorId: 8,
borrows: [
{
id: "5f446f2e2cfa3e1d234679b9",
returned: false,
},
{
id: "5f446f2ed3609b719568a415",
returned: true,
},
...
],
},
I am trying to create a function that will count how many times an account's ID appears in any book's borrow array.
This is my current attempt at the function:
function getTotalNumberOfBorrows(account, books) {
const accId = account.id;
let idBorrowed = books.filter((book) => accId === book.borrows.id);
return idBorrowed.length;
}
However, I am getting 0 as the result instead of the expected 2. As a learner of advanced functions, I have been advised to utilize find, filter, map, reduce, and destructuring objects when necessary. Any guidance or advice would be greatly appreciated. Thank you!