Skip to content

Commit 9ab1869

Browse files
committed
changes
--- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na ---
1 parent 0271a9e commit 9ab1869

File tree

2 files changed

+148
-0
lines changed

2 files changed

+148
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2018 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
/**
22+
* Compute a range incrementally, ignoring `NaN` values.
23+
*
24+
* @module @stdlib/stats/incr/nanrange
25+
*
26+
* @example
27+
* var incrnanrange = require( '@stdlib/stats/incr/nanrange' );
28+
*
29+
* var accumulator = incrnanrange();
30+
*
31+
* var range = accumulator();
32+
* // returns null
33+
*
34+
* range = accumulator( 3.14 );
35+
* // returns 0.0
36+
*
37+
* range = accumulator( NaN );
38+
* // returns 8.14
39+
*
40+
* range = accumulator( -5.0 );
41+
* // returns 8.14
42+
*
43+
* range = accumulator( 10.1 );
44+
* // returns 15.1
45+
*
46+
* range = accumulator();
47+
* // returns 15.1
48+
*/
49+
50+
// MODULES //
51+
52+
var main = require( '@stdlib/stats/incr/nanrange/lib/main.js' );
53+
54+
55+
// EXPORTS //
56+
57+
module.exports = main;
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2018 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var PINF = require( '@stdlib/constants/float64/pinf' );
24+
var NINF = require( '@stdlib/constants/float64/ninf' );
25+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
26+
27+
28+
// MAIN //
29+
30+
/**
31+
* Returns an accumulator function which incrementally computes a range while ignoring NaN values.
32+
*
33+
* @returns {Function} accumulator function
34+
*
35+
* @example
36+
* var accumulator = incrnanrange();
37+
*
38+
* var range = accumulator();
39+
* // returns null
40+
*
41+
* range = accumulator( 3.14 );
42+
* // returns 0.0
43+
*
44+
* range = accumulator( NaN );
45+
* // returns 0.0
46+
*
47+
* range = accumulator( -5.0 );
48+
* // returns 8.14
49+
*
50+
* range = accumulator( 10.1 );
51+
* // returns 15.1
52+
*
53+
* range = accumulator();
54+
* // returns 15.1
55+
*/
56+
function incrnanrange() {
57+
var range;
58+
var max = NINF;
59+
var min = PINF;
60+
61+
return accumulator;
62+
63+
/**
64+
* If provided a value, the accumulator function returns an updated range while ignoring NaN values. If not provided a value, the accumulator function returns the current range.
65+
*
66+
* @private
67+
* @param {number} [x] - new value
68+
* @returns {(number|null)} range or null
69+
*/
70+
function accumulator( x ) {
71+
if ( arguments.length === 0 ) {
72+
return ( range === void 0 ) ? null : range;
73+
}
74+
if ( isnan( x ) ) {
75+
return range;
76+
}
77+
if ( x > max ) {
78+
max = x;
79+
}
80+
if ( x < min ) {
81+
min = x;
82+
}
83+
range = max - min;
84+
return range;
85+
}
86+
}
87+
88+
89+
// EXPORTS //
90+
91+
module.exports = incrnanrange;

0 commit comments

Comments
 (0)