_basePullAt.js 939 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. var baseUnset = require('./_baseUnset'),
  2. isIndex = require('./_isIndex');
  3. /** Used for built-in method references. */
  4. var arrayProto = Array.prototype;
  5. /** Built-in value references. */
  6. var splice = arrayProto.splice;
  7. /**
  8. * The base implementation of `_.pullAt` without support for individual
  9. * indexes or capturing the removed elements.
  10. *
  11. * @private
  12. * @param {Array} array The array to modify.
  13. * @param {number[]} indexes The indexes of elements to remove.
  14. * @returns {Array} Returns `array`.
  15. */
  16. function basePullAt(array, indexes) {
  17. var length = array ? indexes.length : 0,
  18. lastIndex = length - 1;
  19. while (length--) {
  20. var index = indexes[length];
  21. if (length == lastIndex || index !== previous) {
  22. var previous = index;
  23. if (isIndex(index)) {
  24. splice.call(array, index, 1);
  25. } else {
  26. baseUnset(array, index);
  27. }
  28. }
  29. }
  30. return array;
  31. }
  32. module.exports = basePullAt;