README.md (1876B)
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 # incrcount 22 23 > Compute a count incrementally. 24 25 <section class="usage"> 26 27 ## Usage 28 29 ```javascript 30 var incrcount = require( '@stdlib/stats/incr/count' ); 31 ``` 32 33 #### incrcount() 34 35 Returns an accumulator `function` which incrementally computes a count. 36 37 ```javascript 38 var accumulator = incrcount(); 39 ``` 40 41 #### accumulator( \[x] ) 42 43 If provided an input value `x`, the accumulator function returns an updated count. If not provided an input value `x`, the accumulator function returns the current count. 44 45 ```javascript 46 var accumulator = incrcount(); 47 48 var count = accumulator( 2.0 ); 49 // returns 1 50 51 count = accumulator( 1.0 ); 52 // returns 2 53 54 count = accumulator( 3.0 ); 55 // returns 3 56 57 count = accumulator(); 58 // returns 3 59 ``` 60 61 </section> 62 63 <!-- /.usage --> 64 65 <section class="examples"> 66 67 ## Examples 68 69 <!-- eslint no-undef: "error" --> 70 71 ```javascript 72 var randu = require( '@stdlib/random/base/randu' ); 73 var incrcount = require( '@stdlib/stats/incr/count' ); 74 75 var accumulator; 76 var v; 77 var i; 78 79 // Initialize an accumulator: 80 accumulator = incrcount(); 81 82 // For each simulated datum, update the count... 83 for ( i = 0; i < 100; i++ ) { 84 v = randu() * 100.0; 85 accumulator( v ); 86 } 87 console.log( accumulator() ); 88 ``` 89 90 </section> 91 92 <!-- /.examples --> 93 94 <section class="links"> 95 96 </section> 97 98 <!-- /.links -->