@stdlib/utils-if-else
TypeScript icon, indicating that this package has built-in type declarations

0.0.8 • Public • Published

ifelse

NPM version Build Status Coverage Status

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

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 );
}

See Also


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.

Community

Chat


License

See LICENSE.

Copyright

Copyright © 2016-2022. The Stdlib Authors.

Install

npm i @stdlib/utils-if-else

Homepage

stdlib.io

DownloadsWeekly Downloads

31

Version

0.0.8

License

Apache-2.0

Unpacked Size

36.6 kB

Total Files

9

Last publish

Collaborators

  • stdlib-bot
  • kgryte
  • planeshifter
  • rreusser