Commit e7286bd
Changed files (3)
lib/movie_library.js
@@ -165,6 +165,19 @@ module.exports = MovieLibrary = (function(_super) {
});
};
+ MovieLibrary.prototype.sorted_by_studio_rankings_then_by_year_published = function(rankings) {
+ var _this = this;
+ return this.movies.sort(function(x, y) {
+ var result;
+ result = rankings.indexOf(x.studio) - rankings.indexOf(y.studio);
+ if (result === 0) {
+ return x.year_published - y.year_published;
+ } else {
+ return result;
+ }
+ });
+ };
+
return MovieLibrary;
})(Module);
src/movie_library.coffee
@@ -85,3 +85,8 @@ module.exports = class MovieLibrary extends Module
sorted_by_year_published_descending: ->
@movies.sort (x, y) ->
y.year_published - x.year_published
+
+ sorted_by_studio_rankings_then_by_year_published: (rankings) ->
+ @movies.sort (x, y) =>
+ result = rankings.indexOf(x.studio) - rankings.indexOf(y.studio)
+ if result == 0 then (x.year_published - y.year_published) else result
test/movie_library_spec.coffee
@@ -115,10 +115,10 @@ describe "MovieLibrary", ->
results = @sut.sorted_by_year_published()
results.should.eql(expected_order)
- xit 'Sorts all movies by preferred studios and release date ascending', ->
+ it 'Sorts all movies by preferred studios and release date ascending', ->
#rankings: Pixar, Disney, CastleRock, MiramaxFilms, RegenceyEnterprises
- rankings = [Studio::Pixar, Studio::Disney, Studio::CastleRock, Studio::MiramaxFilms, Studio::RegencyEnterprises]
+ rankings = [Studio.Pixar, Studio.Disney, Studio.CastleRock, Studio.MiramaxFilms, Studio.RegencyEnterprises]
expected_order = [ @toy_story, @monsters_inc, @up, @cars, @fantasia, @pinocchio, @dumbo, @shawshank_redemption, @chasing_amy, @man_on_fire ]
- results = @sut.sorted_by_studio_rankings_then_by_year_published()
+ results = @sut.sorted_by_studio_rankings_then_by_year_published(rankings)
results.should.eql(expected_order)