1 var baseCallback = require('../internal/baseCallback'),
2 basePullAt = require('../internal/basePullAt');
5 * Removes all elements from `array` that `predicate` returns truthy for
6 * and returns an array of the removed elements. The predicate is bound to
7 * `thisArg` and invoked with three arguments: (value, index, array).
9 * If a property name is provided for `predicate` the created `_.property`
10 * style callback returns the property value of the given element.
12 * If a value is also provided for `thisArg` the created `_.matchesProperty`
13 * style callback returns `true` for elements that have a matching property
14 * value, else `false`.
16 * If an object is provided for `predicate` the created `_.matches` style
17 * callback returns `true` for elements that have the properties of the given
18 * object, else `false`.
20 * **Note:** Unlike `_.filter`, this method mutates `array`.
25 * @param {Array} array The array to modify.
26 * @param {Function|Object|string} [predicate=_.identity] The function invoked
28 * @param {*} [thisArg] The `this` binding of `predicate`.
29 * @returns {Array} Returns the new array of removed elements.
32 * var array = [1, 2, 3, 4];
33 * var evens = _.remove(array, function(n) {
43 function remove(array, predicate, thisArg) {
45 if (!(array && array.length)) {
50 length = array.length;
52 predicate = baseCallback(predicate, thisArg, 3);
53 while (++index < length) {
54 var value = array[index];
55 if (predicate(value, index, array)) {
60 basePullAt(array, indexes);
64 module.exports = remove;