Table of Content
Getting the book list from tag
We do the intersection based only on ISBN because the simple string value can make best use of the Lo-Dash’s methods.
1data.findBooksByTags = function(tags) { 2 var isbns = this.allIsbns(); // all books by default 3 _.forEach(tags, function(tag){ // loop all tags 4 var isbnsFromTag = data.storage.loadList("tag:" + tag); // get the ISBN list from the tag 5 isbns = _.intersection(isbns, isbnsFromTag); // intersect with the result. 6 }); 7 return this.findBooksByIsbns(isbns); // get back the book list from ISBNs. 8}
We need an array of all book ISBNs. This can be done by list all books and retrieve the ISBN in each book. You may think of a for-loop statement, but the map
function can help.
Since the collection manipulation is based on ISBNs, the last thing we need to do is retrieve the book list from the ISBNs.
What’s next? We’re going to take a look at “Render book list with argument”.