Split filter out.

This commit is contained in:
John-David Dalton
2017-04-16 08:49:26 -05:00
parent 8b74809f1c
commit 64a9975488
4 changed files with 47 additions and 56 deletions

View File

@@ -1,24 +0,0 @@
/**
* A specialized version of `filter` for arrays.
*
* @private
* @param {Array} [array] The array to iterate over.
* @param {Function} predicate The function invoked per iteration.
* @returns {Array} Returns the new filtered array.
*/
function arrayFilter(array, predicate) {
let index = -1
let resIndex = 0
const length = array == null ? 0 : array.length
const result = []
while (++index < length) {
const value = array[index]
if (predicate(value, index, array)) {
result[resIndex++] = value
}
}
return result
}
export default arrayFilter

View File

@@ -1,21 +0,0 @@
import baseEach from './baseEach.js'
/**
* The base implementation of `filter`.
*
* @private
* @param {Array|Object} collection The collection to iterate over.
* @param {Function} predicate The function invoked per iteration.
* @returns {Array} Returns the new filtered array.
*/
function baseFilter(collection, predicate) {
const result = []
baseEach(collection, (value, index, collection) => {
if (predicate(value, index, collection)) {
result.push(value)
}
})
return result
}
export default baseFilter