Skip to content

Instantly share code, notes, and snippets.

@seandaniel
seandaniel / newestMovies.js
Last active July 31, 2020 13:35
5. Return all movies in order of newest first
const moviesReleaseDateDescending = movies.sort((movie1, movie2) => {
if (movie1.releaseDate < movie2.releaseDate) {
return true;
} else {
return false;
}
});
console.log(moviesReleaseDateDescending);
// [
@seandaniel
seandaniel / drama.js
Last active July 31, 2020 13:33
4. Return all movies with the genre Drama
const genresArray = movies.filter((movie) => {
return movie.genre.includes('Drama');
});
console.log(genresArray)
// [
{
name: "Good Will Hunting",
releaseDate: 2011,
genre: ['Drama', 'Romance'],
@seandaniel
seandaniel / average.js
Last active August 11, 2020 17:34
3. Return the average rating of movies
let ratingsAverage = movies.map((movie) => {
return movie.rating;
});
ratingsAverage = ratingsAverage.reduce((total, rating) => {
return (total + rating);
});
console.log(ratingsAverage / movies.length);
// 8.357142857142858
@seandaniel
seandaniel / quentinTarantino.js
Last active July 31, 2020 13:31
2. Return movies directed by Quentin Tarantino
const quentinTarantinoMovies = movies.filter((movie) => {
return movie.director === 'Quentin Tarantino';
});
console.log(quentinTarantinoMovies)
// [
{
name: "Inglourious Basterds",
releaseDate: 2009,
genre: ['Adventure', 'Drama', 'War'],
@seandaniel
seandaniel / movieNames.js
Last active July 31, 2020 13:30
1. Return movie names
const movieNames = movies.map((movie) => {
return movie.name;
});
console.log(movieNames);
// [
"Good Will Hunting",
"Parasite",
"The Shawshank Redemption",
"Inglourious Basterds",
@seandaniel
seandaniel / movies.js
Last active July 31, 2020 13:28
movies array
const movies = [
{
name: "Good Will Hunting",
releaseDate: 1998,
genre: ['Drama', 'Romance'],
rating: 8.3,
director: 'Gus Van Sant'
},
{
name: "Parasite",
@seandaniel
seandaniel / length.js
Last active July 31, 2020 14:07
How to use the length method
const favouriteArtists = ['Anderson .Paak', 'Tame Impala', 'Twenty One Pilots'];
const totalFavouriteArtists = favouriteArtists.length;
console.log(totalFavouriteArtists);
// 3
@seandaniel
seandaniel / slice.js
Last active July 31, 2020 14:07
How to use the slice() method
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'];
@seandaniel
seandaniel / includes.js
Last active July 31, 2020 14:07
How to use the includes() method
const ages = [6, 5, 8, 10];
ages.includes(6)
// true
const fruit = ['Mango', 'Pineapple', 'Dragon Fruit'];
fruit.includes('Apple');
// false
@seandaniel
seandaniel / push.js
Last active July 31, 2020 14:04
How to use the push() method
const groceries = ['bananas', 'milk', 'chicken', 'avocados'];
groceries.push('cookies');
console.log(groceries);
// ['bananas', 'milk', 'chicken', 'avocados', 'cookies']