insert.js 392 B

123456789101112131415
  1. var difference = require('./difference');
  2. var slice = require('./slice');
  3. /**
  4. * Insert item into array if not already present.
  5. */
  6. function insert(arr, rest_items) {
  7. var diff = difference(slice(arguments, 1), arr);
  8. if (diff.length) {
  9. Array.prototype.push.apply(arr, diff);
  10. }
  11. return arr.length;
  12. }
  13. module.exports = insert;