combine.js 508 B

12345678910111213141516171819202122
  1. var indexOf = require('./indexOf');
  2. /**
  3. * Combines an array with all the items of another.
  4. * Does not allow duplicates and is case and type sensitive.
  5. */
  6. function combine(arr1, arr2) {
  7. if (arr2 == null) {
  8. return arr1;
  9. }
  10. var i = -1, len = arr2.length;
  11. while (++i < len) {
  12. if (indexOf(arr1, arr2[i]) === -1) {
  13. arr1.push(arr2[i]);
  14. }
  15. }
  16. return arr1;
  17. }
  18. module.exports = combine;