Skip to content

Commit

Permalink
remove ctx from filter
Browse files Browse the repository at this point in the history
  • Loading branch information
marcuswestin committed May 30, 2013
1 parent 49e02fe commit 0e397e4
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,21 @@
var each = require('./each')
var isArray = require('./isArray')

module.exports = function filter(arr, ctx, fn) {
module.exports = function filter(arr, fn) {
if (!arr) { return [] }
if (arguments.length == 2) {
fn = ctx
ctx = this
}
if (!fn) {
fn = falseOrTruthy
}
if (!fn) { fn = falseOrTruthy }

var result
if (isArray(arr)) {
result = []
each(arr, function(value, index) {
if (!fn.call(ctx, value, index)) { return }
if (!fn(value, index)) { return }
result.push(value)
})
} else {
result = {}
each(arr, function(value, key) {
if (!fn.call(ctx, value, key)) { return }
if (!fn(value, index)) { return }
result[key] = value
})
}
Expand Down

0 comments on commit 0e397e4

Please sign in to comment.