ifelse
If a condition is truthy, return
x; otherwise, returny.
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 ); }
See Also
@stdlib/utils/async/if-else: if a predicate function returns a truthy value, returnx; otherwise, returny.@stdlib/utils/if-then: if a condition is truthy, invokex; otherwise, invokey.