Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion classes/Book.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,29 @@
// import the Media class:
const Media = require("./Media")

// create your Book class:
class Book extends Media {
constructor(title, year, genre, author, numPages, rating) {
super(title, year, genre);
this.author = author;
this.numPages = numPages;
this.rating = rating;
}

summary() {
return `Title: ${this.title}, Author: ${this.author}, Year: ${this.year}, Page Count: ${this.numPages}, Genre: ${this.genre}, Rating: ${this.rating}`
}

static highestRating(arr) {
return arr.sort((a , b) => b.rating - a.rating)[0]
}

static calculateAverageRating(arr) {

const arr_ratings = arr.map((book) => book.rating);
return (arr_ratings.reduce((acc, rating) => acc + rating), 0) / arr_ratings.length;

}
}

// don't change below
module.exports = Book;
18 changes: 18 additions & 0 deletions classes/Media.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
// create your Media class:

const { ALL_MEDIA } = require("./Media");

class Media {
static ALL_MEDIA = [];
static totalMediaCount = 0;
constructor(title, year, genre) {
this.title = title;
this.year = year;
this.genre = genre;
++Media.totalMediaCount;
Media.ALL_MEDIA.push(this);
}

summary() {
return `Title: ${this.title}, Year: ${this.year}, Genre: ${this.genre}`;
}
}

// uncomment below to export it:
module.exports = Media;
21 changes: 20 additions & 1 deletion classes/Movie.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
// import the Media class:

const Media = require("./Media")
// create your Movie class:
class Movie extends Media{
constructor(title, year, genre, director, duration, rating){
super(title, year, genre)
this.director = director;
this.rating = rating;
this.duration = duration

}
summary(){
return `Title: ${this.title}, Director: ${this.director}, Year: ${this.year}, Genre: ${this.genre}, Rating: ${this.rating}`
}
static longestMovie(arr){
return arr.reduce((max,current)=> (current.duration > max.duration ? current:max))
}

static calculateAverageRating(arr) {

return arr.reduce((acc, movie) => acc + movie.rating, 0) / arr.length;
}
}
// don't change below
module.exports = Movie;
26 changes: 25 additions & 1 deletion classes/Music.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
// import the Media class:
const Media = require("./Media");

// create your Music class:

class Music extends Media {
constructor(title, year, genre, artist, length) {
super(title, year, genre);
this.artist = artist;
this.length = length;
}

summary() {
return `Title: ${this.title}, Artist: ${this.artist}, Year: ${this.year}, Genre: ${this.genre}, Length: ${this.length} seconds`;
}

static shortestAlbum(arr) {
let shortestAlbum = new Music();
shortestAlbum.length = 10000000;
for (let i = 0; i < arr.length; ++i) {
if (arr[i].length < shortestAlbum.length) shortestAlbum = arr[i];
}

return shortestAlbum;
}

}


// don't change below
module.exports = Music;
16 changes: 16 additions & 0 deletions classes/Podcast.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const Music = require("./Music");

class Podcast extends Music{
constructor(title, year, genre, artist, length, host,epsiodeName, episodeNumber, guests) {
super(title, year, genre, artist, length);
this.host = host;
this.epsiodeName = epsiodeName;
this.episodeNumber = episodeNumber;
this.guests = guests
}
listen(){
return `${this.title} - Episode: ${this.epsiodeName}. Hosted by ${this.host} and featuring guests ${this.guests}. Length: ${this.length} seconds.`
}
}

module.exports = Podcast;
36 changes: 35 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
@@ -1 +1,35 @@
// Import classes here to console.log and debug
const Media = require("./classes/Media");
const Book = require("./classes/Book");
const Movie = require("./classes/Movie");
const Music = require("./classes/Music");
const Podcast = require("./classes/Podcast");

const movie1 = new Movie(
'Inception',
2010,
'Sci-Fi',
'Christopher Nolan',
148,
10
)
const movie2 = new Movie(
'Inception',
2010,
'Sci-Fi',
'Christopher Nolan',
148,
10
)
const movie3 = new Movie(
'Inception',
2010,
'Sci-Fi',
'Christopher Nolan',
148,
50
)

const music1 = new Music('Lemonade', 2016, 'R&B', 'Beyonce', 3949)
console.log(Media.ALL_MEDIA)