react / wstein / node_modules / jest-cli / node_modules / istanbul / node_modules / js-yaml / node_modules / argparse / node_modules / lodash / array / remove.js
80742 viewsvar baseCallback = require('../internal/baseCallback'),1basePullAt = require('../internal/basePullAt');23/**4* Removes all elements from `array` that `predicate` returns truthy for5* and returns an array of the removed elements. The predicate is bound to6* `thisArg` and invoked with three arguments: (value, index, array).7*8* If a property name is provided for `predicate` the created `_.property`9* style callback returns the property value of the given element.10*11* If a value is also provided for `thisArg` the created `_.matchesProperty`12* style callback returns `true` for elements that have a matching property13* value, else `false`.14*15* If an object is provided for `predicate` the created `_.matches` style16* callback returns `true` for elements that have the properties of the given17* object, else `false`.18*19* **Note:** Unlike `_.filter`, this method mutates `array`.20*21* @static22* @memberOf _23* @category Array24* @param {Array} array The array to modify.25* @param {Function|Object|string} [predicate=_.identity] The function invoked26* per iteration.27* @param {*} [thisArg] The `this` binding of `predicate`.28* @returns {Array} Returns the new array of removed elements.29* @example30*31* var array = [1, 2, 3, 4];32* var evens = _.remove(array, function(n) {33* return n % 2 == 0;34* });35*36* console.log(array);37* // => [1, 3]38*39* console.log(evens);40* // => [2, 4]41*/42function remove(array, predicate, thisArg) {43var result = [];44if (!(array && array.length)) {45return result;46}47var index = -1,48indexes = [],49length = array.length;5051predicate = baseCallback(predicate, thisArg, 3);52while (++index < length) {53var value = array[index];54if (predicate(value, index, array)) {55result.push(value);56indexes.push(index);57}58}59basePullAt(array, indexes);60return result;61}6263module.exports = remove;646566