Skip to content

Latest commit

 

History

History
84 lines (49 loc) · 1.64 KB

File metadata and controls

84 lines (49 loc) · 1.64 KB

ifelse

If a condition is truthy, return x; otherwise, return y.

Usage

var ifelse = require( '@stdlib/utils/if-else' );

ifelse( bool, x, y )

If a condition is truthy, returns x; otherwise, returns y.

var z = ifelse( true, 1.0, -1.0 );
// returns 1.0

z = ifelse( false, 1.0, -1.0 );
// returns -1.0

Examples

var randu = require( '@stdlib/math/base/random/randu' );
var ifelse = require( '@stdlib/utils/if-else' );

var z;
var i;

for ( i = 0; i < 100; i++ ) {
    z = ifelse( randu() > 0.9, 'BOOP', 'beep' );
    console.log( z );
}