@amphibian/filter

1.0.0 • Public • Published

filter

build status

matches items in an array or object that return true in the filtering function

npm install @amphibian/filter
var filter = require('@amphibian/filter');
var array = ['zero', 'one', 'two', 'three', 'four'];

filter(array, (index) => index !== 'zero'); // > ['one', 'two', 'three', 'four']
filter(array, (index, i) => i < 3); // > ['zero', 'one', 'two']

var object = {
    zero: {hello: true},
    one: {hello: false},
    two: {hello: true},
    three: {hello: false}
};

filter(object, (key, value) => value.hello === true); /* > {
    zero: {hello: true},
    two: {hello: true}
} */

// You can also stop the filtering when you're satisfied with the results
var matches = filter(array, (index, i, end, matches) => {
    if (matches.length < 3) {
        return true;
    } else {
        end();
    }
});

console.log(matches); // > ['zero', 'one', 'two']

Readme

Keywords

none

Package Sidebar

Install

npm i @amphibian/filter

Weekly Downloads

1

Version

1.0.0

License

ISC

Last publish

Collaborators

  • thomaslindstr_m