echo75 / my-movie-db

MIT License
1 stars 0 forks source link

#CleanCode Rule of Three #21

Closed Dr4gon closed 1 year ago

Dr4gon commented 1 year ago

@echo75 The last two functions are exactly the same and the first is similiar. How would one general function for these look like?

user.js

  reviewsMovie(imdbID) {
    const filteredReviews = this.reviews.filter(review => review.imdbID === imdbID)
    //console.log('filteredReviews', filteredReviews)
    const result =
      filteredReviews.length === 0
        ? 'No reviews for this movie'
        : filteredReviews
            .map(
              (element, index) =>
                `${index + 1}. ${element.text} -> Movie:(${element.imdbID}), says User: ${this.firstName}`
            )
            .join('\n')
    return `--- Review-List ---\n${result}\n`
  }

  onWatch() {
    // onWatchInfo
    const result =
      this.watch === 0
        ? 'No movies are put on the watch-list'
        : this.watch
            .map((element, index) => `${index + 1}. ${element.Title} (${element.Year}) (firstName: ${this.firstName})`)
            .join('\n')
    return `--- Watch-List ---\n${result}\n`
  }

  onWatched() {
    // onWatchedInfo
    const result =
      this.watched === 0
        ? 'No movies are put on the watched-list'
        : this.watched
            .map((element, index) => `${index + 1}. ${element.Title} (${element.Year}) (firstName: ${this.firstName})`)
            .join('\n')
    return `--- Watched-List ---\n${result}\n`
  }
ghost commented 1 year ago

You could delete this methods as they are old getters and not used for the application

echo75 commented 1 year ago

This was legacy code, that wasn't used - it is removed now