README.md (3261B)
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 # itercumax 22 23 > Create an [iterator][mdn-iterator-protocol] which iteratively computes a cumulative maximum value. 24 25 <section class="intro"> 26 27 </section> 28 29 <!-- /.intro --> 30 31 <!-- Package usage documentation. --> 32 33 <section class="usage"> 34 35 ## Usage 36 37 ```javascript 38 var itercumax = require( '@stdlib/stats/iter/cumax' ); 39 ``` 40 41 #### itercumax( iterator ) 42 43 Returns an [iterator][mdn-iterator-protocol] which iteratively computes a cumulative maximum value. 44 45 ```javascript 46 var array2iterator = require( '@stdlib/array/to-iterator' ); 47 48 var arr = array2iterator( [ 2.0, 1.0, 3.0, -7.0, -5.0 ] ); 49 var it = itercumax( arr ); 50 51 var m = it.next().value; 52 // returns 2.0 53 54 m = it.next().value; 55 // returns 2.0 56 57 m = it.next().value; 58 // returns 3.0 59 60 m = it.next().value; 61 // returns 3.0 62 63 m = it.next().value; 64 // returns 3.0 65 ``` 66 67 </section> 68 69 <!-- /.usage --> 70 71 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 72 73 <section class="notes"> 74 75 ## Notes 76 77 - If an iterated value is non-numeric (including `NaN`), the function returns `NaN` for **all** future iterations. 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. 78 79 </section> 80 81 <!-- /.notes --> 82 83 <!-- Package usage examples. --> 84 85 <section class="examples"> 86 87 ## Examples 88 89 <!-- eslint no-undef: "error" --> 90 91 ```javascript 92 var runif = require( '@stdlib/random/iter/uniform' ); 93 var itercumax = require( '@stdlib/stats/iter/cumax' ); 94 95 // Create an iterator for generating uniformly distributed pseudorandom numbers: 96 var rand = runif( -10.0, 10.0, { 97 'seed': 1234, 98 'iter': 100 99 }); 100 101 // Create an iterator for iteratively computing a cumulative maximum value: 102 var it = itercumax( rand ); 103 104 // Perform manual iteration... 105 var v; 106 while ( true ) { 107 v = it.next(); 108 if ( typeof v.value === 'number' ) { 109 console.log( 'max: %d', v.value ); 110 } 111 if ( v.done ) { 112 break; 113 } 114 } 115 ``` 116 117 </section> 118 119 <!-- /.examples --> 120 121 <!-- 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. --> 122 123 <section class="references"> 124 125 </section> 126 127 <!-- /.references --> 128 129 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 130 131 <section class="links"> 132 133 [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol 134 135 </section> 136 137 <!-- /.links -->