everyInBy

Test whether all properties (own and inherited) of an object pass a test implemented by a predicate function.

Usage

var everyInBy = require( '@stdlib/utils/every-in-by' );

everyInBy( object, predicate[, thisArg ] )

Tests whether all properties (own and inherited) of an object pass a test implemented by a predicate function.

var o;
var bool;

function isPositive( v ) {
    return ( v > 0 );
}

o = {
    'a': 1,
    'b': 2,
    'c': 3
};

bool = everyInBy( o, isPositive );
// returns true

If provided an empty object, the function returns true.

function isPositive(v) {
    return ( v > 0 );
}

var bool = everyInBy( {}, isPositive );
// returns true

Examples

var randu = require( '@stdlib/random/base/randu' );
var everyInBy = require( '@stdlib/utils/every-in-by' );

var bool;
var o;
var i;

function isPositive(v) {
    return ( v > 0 );
}

o = {};
for ( i = 0; i < 100; i++ ) {
    o[ i ] = ( randu() < 0.95 );
}

bool = everyInBy( o, isPositive );
// returns <boolean>
Did you find this page helpful?