hoping someone can point me in the right direction here. I have to add the pages of each book and get a total at the end. I was able to do a function that pulls the values from the pages attribute, now what would I have to use in order to add those values.
var library = {
book: 'A',
pages: 1,
next: {
book: 'B',
pages: 2,
next: {
book: 'C',
pages: 3,
next: null
} //end of book c
} //end of book b
} //end of library
function getPageCount(list) { //start of function
var p = []
if(list.next) p = p.concat(getPageCount(list.next));
p.push(list.pages)
return p
} //end of function getPageCount
console.log(getPageCount(library))
So this is what I have, running it will output [ 3, 2, 1] in console log, I now need to have it be something similar to [3 + 2 + 1 = 6]
Would array.reduce work here? Is it something simple and I just don't see it myself.
Thanks in advance!