replaceHolders.js 738 B

12345678910111213141516171819202122232425262728
  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 = -1,
  16. result = [];
  17. while (++index < length) {
  18. if (array[index] === placeholder) {
  19. array[index] = PLACEHOLDER;
  20. result[++resIndex] = index;
  21. }
  22. }
  23. return result;
  24. }
  25. module.exports = replaceHolders;