array-filter
Advanced tools
Comparing version 0.0.1 to 0.1.0
@@ -6,6 +6,7 @@ /** | ||
* @param {Function} fn | ||
* @param {Object=} self | ||
* @return {Array} | ||
*/ | ||
module.exports = function (arr, fn) { | ||
module.exports = function (arr, fn, self) { | ||
if (arr.filter) return arr.filter(fn); | ||
@@ -15,3 +16,3 @@ var ret = []; | ||
if (!hasOwn.call(arr, i)) continue; | ||
if (fn(arr[i], i, arr)) ret.push(arr[i]); | ||
if (fn.call(self, arr[i], i, arr)) ret.push(arr[i]); | ||
} | ||
@@ -18,0 +19,0 @@ return ret; |
{ | ||
"name": "array-filter", | ||
"description": "Array#filter for older browsers.", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"repository": { | ||
@@ -6,0 +6,0 @@ "type": "git", |
@@ -22,2 +22,14 @@ | ||
## API | ||
### filter(arr, fn[, self]) | ||
Return an array with elements of `arr` for which `fn` returns a truthy value. `fn` is called with | ||
* `el`: The current element | ||
* `i`: The element's index | ||
* `arr`: The whole array | ||
Optionally pass in `self` as the `this` value for `fn`. | ||
## Installation | ||
@@ -24,0 +36,0 @@ |
@@ -6,3 +6,3 @@ var filter = require('..'); | ||
var arr = [1, 2, 3, 4, 5]; | ||
delete arr.filter; | ||
arr.filter = undefined; | ||
var even = filter(arr, function(el) { | ||
@@ -9,0 +9,0 @@ return el % 2 == 0; |
@@ -6,3 +6,3 @@ var filter = require('..'); | ||
var arr = new Array(5); | ||
delete arr.filter; | ||
arr.filter = undefined; | ||
var res = filter(arr, function(el) { | ||
@@ -9,0 +9,0 @@ return false; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4284
8
51
67