difference.js 608 B

1234567891011121314151617181920212223
  1. var unique = require('./unique');
  2. var filter = require('./filter');
  3. var some = require('./some');
  4. var contains = require('./contains');
  5. var slice = require('./slice');
  6. /**
  7. * Return a new Array with elements that aren't present in the other Arrays.
  8. */
  9. function difference(arr) {
  10. var arrs = slice(arguments, 1),
  11. result = filter(unique(arr), function(needle){
  12. return !some(arrs, function(haystack){
  13. return contains(haystack, needle);
  14. });
  15. });
  16. return result;
  17. }
  18. module.exports = difference;