time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

README.md (3413B)


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