forked from CodeYourFuture/Module-JS1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray-of-objects.js
More file actions
81 lines (76 loc) · 2.11 KB
/
Copy patharray-of-objects.js
File metadata and controls
81 lines (76 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
This exercise includes an array of objects. You can read more about objects here: https://javascript.info/object
Imagine you're working for an online store selling books (like Amazon).
Below, we have an array of book objects.
Each object contains the title of the book, the genre, and a rating based on user reviews.
We want to find the title of the highest rated book in each genre to showcase on our home page.
Implement a function which takes the array of books as a parameter, and returns an array of book titles.
Each title in the resulting array should be the highest rated book in its genre.
*/
function getHighestRatedInEachGenre(books) {
// TODO
}
/* ======= Book data - DO NOT MODIFY ===== */
const BOOKS = [
{
title: "The Lion, the Witch and the Wardrobe",
genre: "children",
rating: 4.7,
},
{
title: "Sapiens: A Brief History of Humankind",
genre: "non-fiction",
rating: 4.7,
},
{
title: "Nadiya's Fast Flavours",
genre: "cooking",
rating: 4.7,
},
{
title: "Harry Potter and the Philosopher's Stone",
genre: "children",
rating: 4.8,
},
{
title: "A Life on Our Planet",
genre: "non-fiction",
rating: 4.8,
},
{
title:
"Dishoom: The first ever cookbook from the much-loved Indian restaurant",
genre: "cooking",
rating: 4.85,
},
{
title: "Gangsta Granny Strikes Again!",
genre: "children",
rating: 4.9,
},
{
title: "Diary of a Wimpy Kid",
genre: "children",
rating: 4.6,
},
{
title: "BOSH!: Simple recipes. Unbelievable results. All plants.",
genre: "cooking",
rating: 4.6,
},
{
title: "The Book Your Dog Wishes You Would Read",
genre: "non-fiction",
rating: 4.85,
},
];
/* ======= TESTS - DO NOT MODIFY ===== */
test("should return the highest rated book in each genre", () => {
expect(new Set(getHighestRatedInEachGenre(BOOKS))).toEqual(
new Set([
"The Book Your Dog Wishes You Would Read",
"Gangsta Granny Strikes Again!",
"Dishoom: The first ever cookbook from the much-loved Indian restaurant",
])
);
});