Skip to content

Instantly share code, notes, and snippets.

@blakehaswell
Created November 29, 2013 03:33
Show Gist options
  • Save blakehaswell/7701246 to your computer and use it in GitHub Desktop.
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.
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