Skip to content

Commit

Permalink
Finished iterations 1-5
Browse files Browse the repository at this point in the history
  • Loading branch information
nathidaum committed Oct 9, 2024
1 parent 4a88069 commit 98a3306
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/movies.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,28 @@ function dramaMoviesScore(moviesArray) {
};

// Iteration 5: Ordering by year - Order by year, ascending (in growing order)
function orderByYear(moviesArray) {}
function orderByYear(moviesArray) {
const sortedMoviesArr = moviesArray.slice();

sortedMoviesArr.sort((a,b) => {
if(a.year === b.year) {
return a.title.localeCompare(b.title)
} else {
return a.year - b.year;}
});
return sortedMoviesArr;
};

// Iteration 6: Alphabetic Order - Order by title and print the first 20 titles
function orderAlphabetically(moviesArray) {}
function orderAlphabetically(moviesArray) {
const twentyTitlesArray = moviesArray.slice();

const sortedArray = twentyTitlesArray.sort((a,b) => a.title.localeCompare(b.title));
const sortedTitleArray = sortedArray.map((movieObj) => movieObj.title);
const shorterTitleArray = sortedTitleArray.slice(0,20);

return shorterTitleArray;
};

// BONUS - Iteration 7: Time Format - Turn duration of the movies from hours to minutes
function turnHoursToMinutes(moviesArray) {}
Expand Down

0 comments on commit 98a3306

Please sign in to comment.