You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
785 B

4 years ago
  1. /** Used as the internal argument placeholder. */
  2. var PLACEHOLDER = '__lodash_placeholder__';
  3. /**
  4. * Replaces all `placeholder` elements in `array` with an internal placeholder
  5. * and returns an array of their indexes.
  6. *
  7. * @private
  8. * @param {Array} array The array to modify.
  9. * @param {*} placeholder The placeholder to replace.
  10. * @returns {Array} Returns the new array of placeholder indexes.
  11. */
  12. function replaceHolders(array, placeholder) {
  13. var index = -1,
  14. length = array.length,
  15. resIndex = 0,
  16. result = [];
  17. while (++index < length) {
  18. var value = array[index];
  19. if (value === placeholder || value === PLACEHOLDER) {
  20. array[index] = PLACEHOLDER;
  21. result[resIndex++] = index;
  22. }
  23. }
  24. return result;
  25. }
  26. module.exports = replaceHolders;