UNPKG

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