let apressBooks = [
{
name : "beginners",
bookDetails : [
{
"id": 111,
"title": "C# 6.0",
"author": "ANDREW TROELSEN",
"rating": [4.7],
"reviews": [{good : 4 ,
excellent : 12}]
},
{
"id": 222,
"title": "Efficient Learning
Machines",
"author": "Rahul Khanna",
"rating": [4.5],
"reviews": []
}
]
},
{
name : "pro",
bookDetails : [
{
"id": 333,
"title": "Pro AngularJS",
"author": "Adam Freeman",
"rating": [4.0],
"reviews": []
},
{
"id": 444,
"title": "Pro ASP.NET",
"author": "Adam Freeman",
"rating": [4.2],
"reviews": [{good : 14 ,
excellent : 12}]
}
]
}
];
map(apressBooks,(book) => {
return book.bookDetails
})
[ [ { id: 111,
title: 'C# 6.0',
author: 'ANDREW TROELSEN',
rating: [Object],
reviews: [Object] },
{ id: 222,
title: 'Efficient Learning Machines',
author: 'Rahul Khanna',
rating: [Object],
reviews: [] } ],
[ { id: 333,
title: 'Pro AngularJS',
author: 'Adam Freeman',
rating: [Object],
reviews: [] },
{ id: 444,
title: 'Pro ASP.NET',
author: 'Adam Freeman',
rating: [Object],
reviews: [Object] } ] ]
const concatAll = (array,fn) => {
let results = []
for(const value of array)
results.push.apply(results, value);
return results;
}
concatAll(
map(apressBooks,(book) => {
return book.bookDetails
}) )
[ { id: 111,
title: 'C# 6.0',
author: 'ANDREW TROELSEN',
rating: [ 4.7 ],
reviews: [ [Object] ] },
{ id: 222,
title: 'Efficient Learning Machines',
author: 'Rahul Khanna',
rating: [ 4.5 ],
reviews: [] },
{ id: 333,
title: 'Pro AngularJS',
author: 'Adam Freeman',
rating: [ 4 ],
reviews: [] },
{ id: 444,
title: 'Pro ASP.NET',
author: 'Adam Freeman',
rating: [ 4.2 ],
reviews: [ [Object] ] } ]
let goodRatingCriteria = (book) => book.rating[0] > 4.5;
filter(
concatAll(
map(apressBooks,(book) => {
}) )
return book.bookDetails
[ { id: 111,
title: 'C# 6.0',
author: 'ANDREW TROELSEN',
rating: [ 4.7 ],
reviews: [ [Object] ] } ]
Let’s now tweak the apressBooks array a bit, so that we have a data structure that looks like the one shown
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.