Created
November 29, 2013 03:33
-
-
Save blakehaswell/7701246 to your computer and use it in GitHub Desktop.
Returns the unique models from any Backbone collections passed in. Just some fun with functional programming.
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
var _ = require('underscore'); | |
module.exports = function () { | |
var collectionArray = _.toArray(arguments); | |
return _.reduce(collectionArray, function (memo, collection) { | |
return memo.concat(collection.reject(function (model) { | |
return _.contains(_.pluck(memo, 'id'), model.id); | |
})); | |
}, []); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment