completed 4.5
This commit is contained in:
parent
160402f147
commit
0309a2cc95
3 changed files with 60 additions and 1 deletions
|
|
@ -27,9 +27,25 @@ const totalLikes = (posts) => {
|
|||
return likeCount;
|
||||
};
|
||||
|
||||
const favoritePost = (posts) => {
|
||||
if (!posts || posts.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const highestLikes = posts.reduce(
|
||||
(max, post) => (post.likes > max ? (max = post.likes) : max),
|
||||
0
|
||||
);
|
||||
|
||||
const favoritePost = posts.find((post) => post.likes == highestLikes);
|
||||
|
||||
return favoritePost;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
reverse,
|
||||
average,
|
||||
listHelper,
|
||||
totalLikes,
|
||||
favoritePost,
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue