README.md (2303B)
1 <!-- 2 3 @license Apache-2.0 4 5 Copyright (c) 2018 The Stdlib Authors. 6 7 Licensed under the Apache License, Version 2.0 (the "License"); 8 you may not use this file except in compliance with the License. 9 You may obtain a copy of the License at 10 11 http://www.apache.org/licenses/LICENSE-2.0 12 13 Unless required by applicable law or agreed to in writing, software 14 distributed under the License is distributed on an "AS IS" BASIS, 15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 See the License for the specific language governing permissions and 17 limitations under the License. 18 19 --> 20 21 # ifelse 22 23 > If a condition is truthy, return `x`; otherwise, return `y`. 24 25 <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> 26 27 <section class="intro"> 28 29 </section> 30 31 <!-- /.intro --> 32 33 <!-- Package usage documentation. --> 34 35 <section class="usage"> 36 37 ## Usage 38 39 ```javascript 40 var ifelse = require( '@stdlib/utils/if-else' ); 41 ``` 42 43 #### ifelse( bool, x, y ) 44 45 If a condition is truthy, returns `x`; otherwise, returns `y`. 46 47 ```javascript 48 var z = ifelse( true, 1.0, -1.0 ); 49 // returns 1.0 50 51 z = ifelse( false, 1.0, -1.0 ); 52 // returns -1.0 53 ``` 54 55 </section> 56 57 <!-- /.usage --> 58 59 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 60 61 <section class="notes"> 62 63 </section> 64 65 <!-- /.notes --> 66 67 <!-- Package usage examples. --> 68 69 <section class="examples"> 70 71 ## Examples 72 73 <!-- eslint no-undef: "error" --> 74 75 ```javascript 76 var randu = require( '@stdlib/random/base/randu' ); 77 var ifelse = require( '@stdlib/utils/if-else' ); 78 79 var z; 80 var i; 81 82 for ( i = 0; i < 100; i++ ) { 83 z = ifelse( randu() > 0.9, 'BOOP', 'beep' ); 84 console.log( z ); 85 } 86 ``` 87 88 </section> 89 90 <!-- /.examples --> 91 92 <!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 93 94 <section class="references"> 95 96 </section> 97 98 <!-- /.references --> 99 100 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 101 102 <section class="links"> 103 104 </section> 105 106 <!-- /.links -->