Skip to content

Commit

Permalink
Finished first 4 iterations
Browse files Browse the repository at this point in the history
  • Loading branch information
vladys00 committed Sep 28, 2024
1 parent a734f2c commit 0dc0f59
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Remember to read each iteration description carefully before working on the solu
### Iteration 1: All directors

We need to get the array of all directors. Since this is a warm up, we will give you a hint: you have to _map_ through the array of movies and get all the directors into one array as a final result. Go ahead and create a function named `getAllDirectors()` that receives an array of movies as an argument and returns a new (_mapped_) array.

  
<br>

#### Bonus - Iteration 1.1: _Clean_ the array of directors
Expand Down
38 changes: 36 additions & 2 deletions src/movies.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,44 @@ function howManyMovies(moviesArray) {
}

// Iteration 3: All scores average - Get the average of all scores with 2 decimals
function scoresAverage(moviesArray) {}
function scoresAverage(moviesArray) {
if (moviesArray.length === 0) {
return 0;
}
const totalScore = moviesArray.reduce(function (curr, object){

return curr + (object.score || 0);
},0)

const totalAverage = totalScore / moviesArray.length;

return Number(totalAverage.toFixed(2));
}

// Iteration 4: Drama movies - Get the average of Drama Movies
function dramaMoviesScore(moviesArray) {}
function dramaMoviesScore(moviesArray) {
const dramaFiltered = moviesArray.filter(function (object){
if (dramaFiltered === 0) {
return 0;
}
return object.genre.includes("Drama");
})
const totalDramaScore = dramaFiltered.reduce(function (curr, object){


return curr + (object.score || 0);

},0)

console.log(totalDramaScore)


const average = totalDramaScore / dramaFiltered.length;

return Number(average.toFixed(2))


}

// Iteration 5: Ordering by year - Order by year, ascending (in growing order)
function orderByYear(moviesArray) {}
Expand Down

0 comments on commit 0dc0f59

Please sign in to comment.