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/random/base/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 );
}