_basePullAt.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. var castPath = require('./_castPath'),
  2. isIndex = require('./_isIndex'),
  3. isKey = require('./_isKey'),
  4. last = require('./last'),
  5. parent = require('./_parent'),
  6. toKey = require('./_toKey');
  7. /** Used for built-in method references. */
  8. var arrayProto = Array.prototype;
  9. /** Built-in value references. */
  10. var splice = arrayProto.splice;
  11. /**
  12. * The base implementation of `_.pullAt` without support for individual
  13. * indexes or capturing the removed elements.
  14. *
  15. * @private
  16. * @param {Array} array The array to modify.
  17. * @param {number[]} indexes The indexes of elements to remove.
  18. * @returns {Array} Returns `array`.
  19. */
  20. function basePullAt(array, indexes) {
  21. var length = array ? indexes.length : 0,
  22. lastIndex = length - 1;
  23. while (length--) {
  24. var index = indexes[length];
  25. if (length == lastIndex || index !== previous) {
  26. var previous = index;
  27. if (isIndex(index)) {
  28. splice.call(array, index, 1);
  29. }
  30. else if (!isKey(index, array)) {
  31. var path = castPath(index),
  32. object = parent(array, path);
  33. if (object != null) {
  34. delete object[toKey(last(path))];
  35. }
  36. }
  37. else {
  38. delete array[toKey(index)];
  39. }
  40. }
  41. }
  42. return array;
  43. }
  44. module.exports = basePullAt;