2d4c517520fdbded5664a7a9eb6472ca5c88b7ef
[platform/framework/web/crosswalk-tizen.git] /
1 var baseIndexOf = require('../internal/baseIndexOf');
2
3 /** Used for native method references. */
4 var arrayProto = Array.prototype;
5
6 /** Native method references. */
7 var splice = arrayProto.splice;
8
9 /**
10  * Removes all provided values from `array` using `SameValueZero` for equality
11  * comparisons.
12  *
13  * **Notes:**
14  *  - Unlike `_.without`, this method mutates `array`
15  *  - [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)
16  *    comparisons are like strict equality comparisons, e.g. `===`, except
17  *    that `NaN` matches `NaN`
18  *
19  * @static
20  * @memberOf _
21  * @category Array
22  * @param {Array} array The array to modify.
23  * @param {...*} [values] The values to remove.
24  * @returns {Array} Returns `array`.
25  * @example
26  *
27  * var array = [1, 2, 3, 1, 2, 3];
28  *
29  * _.pull(array, 2, 3);
30  * console.log(array);
31  * // => [1, 1]
32  */
33 function pull() {
34   var args = arguments,
35       array = args[0];
36
37   if (!(array && array.length)) {
38     return array;
39   }
40   var index = 0,
41       indexOf = baseIndexOf,
42       length = args.length;
43
44   while (++index < length) {
45     var fromIndex = 0,
46         value = args[index];
47
48     while ((fromIndex = indexOf(array, value, fromIndex)) > -1) {
49       splice.call(array, fromIndex, 1);
50     }
51   }
52   return array;
53 }
54
55 module.exports = pull;