Skip to content

Commit

Permalink
Ejercicio 5
Browse files Browse the repository at this point in the history
  • Loading branch information
raulBric committed Mar 7, 2024
1 parent 6e76fa5 commit 2e78246
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/films.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Expand Down

0 comments on commit 2e78246

Please sign in to comment.