summaryrefslogtreecommitdiff
path: root/tools/eslint/node_modules/escope/node_modules/es6-map/node_modules/es5-ext/array/#/filter/shim.js
blob: b0116defce5021a6a45612682d262b86a5eb64e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
'use strict';

var isPlainArray = require('../../is-plain-array')
  , callable     = require('../../../object/valid-callable')

  , isArray = Array.isArray, filter = Array.prototype.filter
  , forEach = Array.prototype.forEach, call = Function.prototype.call;

module.exports = function (callbackFn/*, thisArg*/) {
	var result, thisArg, i;
	if (!this || !isArray(this) || isPlainArray(this)) {
		return filter.apply(this, arguments);
	}
	callable(callbackFn);
	thisArg = arguments[1];
	result = new this.constructor();
	i = 0;
	forEach.call(this, function (val, j, self) {
		if (call.call(callbackFn, thisArg, val, j, self)) result[i++] = val;
	});
	return result;
};