Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/prestaul/fast-filter
Array filtering faster than the native array.filter method
https://github.com/prestaul/fast-filter
Last synced: 2 months ago
JSON representation
Array filtering faster than the native array.filter method
- Host: GitHub
- URL: https://github.com/prestaul/fast-filter
- Owner: Prestaul
- License: mit
- Created: 2015-01-15T06:44:03.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2017-03-23T14:31:03.000Z (almost 8 years ago)
- Last Synced: 2024-09-30T23:38:27.464Z (3 months ago)
- Language: JavaScript
- Size: 5.86 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fast-filter
A replacement for the native `[].filter` method that performs ~5-10 times faster~ [about twice as fast](http://jsperf.com/fastfilter-vs-native-array-filter) in most environments. (Note: As JS engine performance keeps improving, this module becomes less relevant. YMMV.)
## Install
```bash
npm install fast-filter
```## Basic usage
```js
var fastFilter = require('fast-filter');fastFilter([1,2,3,4,5,6], function(val) { return val % 2; }); // [1,3,5]
```## "Installing" on the Array.prototype
You can add `fastFilter` to the native `Array.prototype` for convienience.
```js
require('fast-filter').install();[1,2,3,4,5,6].fastFilter(function(val) { return val % 2; }); // [1,3,5]
```Or provide an alias:
```js
require('fast-filter').install('select');[1,2,3,4,5,6].select(function(val) { return val % 2; }); // [1,3,5]
```## Replacing the native `filter` method
You can replace the native `Array.prototype.filter` method, but keep in mind that this will modify the `filter` method for all code in this instance including any required modules and may result in unexpected behavior.
```js
require('fast-filter').install('filter');[1,2,3,4,5,6].filter(function(val) { return val % 2; }); // [1,3,5]
```