Package Exports
- @stdlib/utils-if-else
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@stdlib/utils-if-else) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
ifelse
If a condition is truthy, return
x
; otherwise, returny
.
Installation
$ npm install @stdlib/utils-if-else
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 );
}
Notice
This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
License
See LICENSE.
Copyright
Copyright © 2016-2021. The Stdlib Authors.