This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const moviesReleaseDateDescending = movies.sort((movie1, movie2) => { | |
if (movie1.releaseDate < movie2.releaseDate) { | |
return true; | |
} else { | |
return false; | |
} | |
}); | |
console.log(moviesReleaseDateDescending); | |
// [ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const genresArray = movies.filter((movie) => { | |
return movie.genre.includes('Drama'); | |
}); | |
console.log(genresArray) | |
// [ | |
{ | |
name: "Good Will Hunting", | |
releaseDate: 2011, | |
genre: ['Drama', 'Romance'], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let ratingsAverage = movies.map((movie) => { | |
return movie.rating; | |
}); | |
ratingsAverage = ratingsAverage.reduce((total, rating) => { | |
return (total + rating); | |
}); | |
console.log(ratingsAverage / movies.length); | |
// 8.357142857142858 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const quentinTarantinoMovies = movies.filter((movie) => { | |
return movie.director === 'Quentin Tarantino'; | |
}); | |
console.log(quentinTarantinoMovies) | |
// [ | |
{ | |
name: "Inglourious Basterds", | |
releaseDate: 2009, | |
genre: ['Adventure', 'Drama', 'War'], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const movieNames = movies.map((movie) => { | |
return movie.name; | |
}); | |
console.log(movieNames); | |
// [ | |
"Good Will Hunting", | |
"Parasite", | |
"The Shawshank Redemption", | |
"Inglourious Basterds", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const movies = [ | |
{ | |
name: "Good Will Hunting", | |
releaseDate: 1998, | |
genre: ['Drama', 'Romance'], | |
rating: 8.3, | |
director: 'Gus Van Sant' | |
}, | |
{ | |
name: "Parasite", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const favouriteArtists = ['Anderson .Paak', 'Tame Impala', 'Twenty One Pilots']; | |
const totalFavouriteArtists = favouriteArtists.length; | |
console.log(totalFavouriteArtists); | |
// 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const randomTorontoInfo = ['CN Tower', 'Partly Cloudy', '20°C', 'Blue Jays', 'Doug Ford', 'The Six']; | |
const weatherToronto = randomTorontoInfo.slice(1, 3); | |
console.log(weatherToronto) | |
// ['Partly Cloudy', '20°C'] | |
console.log(randomTorontoInfo); | |
// ['CN Tower', 'Partly Cloudy', '20°C', 'Blue Jays', 'Doug Ford', 'The Six']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ages = [6, 5, 8, 10]; | |
ages.includes(6) | |
// true | |
const fruit = ['Mango', 'Pineapple', 'Dragon Fruit']; | |
fruit.includes('Apple'); | |
// false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const groceries = ['bananas', 'milk', 'chicken', 'avocados']; | |
groceries.push('cookies'); | |
console.log(groceries); | |
// ['bananas', 'milk', 'chicken', 'avocados', 'cookies'] |