README.md (2988B)
1 <!-- 2 3 @license Apache-2.0 4 5 Copyright (c) 2019 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 # iterrange 22 23 > Compute the [range][range] of all [iterated][mdn-iterator-protocol] values. 24 25 <section class="intro"> 26 27 The [**range**][range] is defined as the difference between the maximum and minimum values. 28 29 </section> 30 31 <!-- /.intro --> 32 33 <!-- Package usage documentation. --> 34 35 <section class="usage"> 36 37 ## Usage 38 39 ```javascript 40 var iterrange = require( '@stdlib/stats/iter/range' ); 41 ``` 42 43 #### iterrange( iterator ) 44 45 Computes the [range][range] of all [iterated][mdn-iterator-protocol] values. 46 47 ```javascript 48 var array2iterator = require( '@stdlib/array/to-iterator' ); 49 50 var arr = array2iterator( [ 1.0, -2.0, 3.0, -4.0 ] ); 51 52 var v = iterrange( arr ); 53 // returns 7.0 54 ``` 55 56 </section> 57 58 <!-- /.usage --> 59 60 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 61 62 <section class="notes"> 63 64 ## Notes 65 66 - If an iterated value is non-numeric (including `NaN`), the returned [`iterator`][mdn-iterator-protocol] returns `NaN`. If non-numeric iterated values are possible, you are advised to provide an [`iterator`][mdn-iterator-protocol] which type checks and handles non-numeric values accordingly. 67 68 </section> 69 70 <!-- /.notes --> 71 72 <!-- Package usage examples. --> 73 74 <section class="examples"> 75 76 ## Examples 77 78 <!-- eslint no-undef: "error" --> 79 80 ```javascript 81 var runif = require( '@stdlib/random/iter/uniform' ); 82 var iterrange = require( '@stdlib/stats/iter/range' ); 83 84 // Create an iterator for generating uniformly distributed pseudorandom numbers: 85 var rand = runif( -10.0, 10.0, { 86 'seed': 1234, 87 'iter': 100 88 }); 89 90 // Compute the range: 91 var v = iterrange( rand ); 92 // returns <number> 93 94 console.log( 'Range: %d.', v ); 95 ``` 96 97 </section> 98 99 <!-- /.examples --> 100 101 <!-- 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. --> 102 103 <section class="references"> 104 105 </section> 106 107 <!-- /.references --> 108 109 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 110 111 <section class="links"> 112 113 [range]: https://en.wikipedia.org/wiki/Range_%28statistics%29 114 115 [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol 116 117 </section> 118 119 <!-- /.links -->