From 2e78246aa9cda4eb3b2e90ea9e31fb2543acc93b Mon Sep 17 00:00:00 2001 From: Raul Date: Thu, 7 Mar 2024 09:57:12 +0100 Subject: [PATCH] Ejercicio 5 --- src/films.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/films.js b/src/films.js index 18bd481..5612e66 100644 --- a/src/films.js +++ b/src/films.js @@ -38,10 +38,19 @@ function orderAlphabetically(array) { } // Exercise 5: Order by year, ascending -function orderByYear() { +function orderByYear(array) { + let result = array.map(item => ({ ...item })).sort((a, b) => { + if (a.year === b.year) { + return a.title.localeCompare(b.title); + } + return a.year - b.year; + }); + return result; } + + // Exercise 6: Calculate the average of the movies in a category function moviesAverageByCategory() {