1.0.0 • Published 7 years ago

@amphibian/filter v1.0.0

Weekly downloads
3
License
ISC
Repository
gitlab
Last release
7 years ago

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']