Skip to content

Commit a59e05e

Browse files
committed
added docs
1 parent 1b8777a commit a59e05e

File tree

3 files changed

+185
-0
lines changed

3 files changed

+185
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
2+
{{alias}}( W )
3+
Returns an accumulator function which incrementally computes a moving
4+
minimum value. ignoring `NaN` values.
5+
6+
The `W` parameter defines the number of values over which to compute the
7+
moving minimum.
8+
9+
If provided a value, the accumulator function returns an updated moving
10+
minimum. If not provided a value, the accumulator function returns the
11+
current moving minimum.
12+
13+
As `W` values are needed to fill the window buffer, the first `W-1` returned
14+
values are calculated from smaller sample sizes. Until the window is full,
15+
each returned value is calculated from all provided values.
16+
17+
Parameters
18+
----------
19+
W: integer
20+
Window size.
21+
22+
Returns
23+
-------
24+
acc: Function
25+
Accumulator function.
26+
27+
Examples
28+
--------
29+
> var accumulator = {{alias}}( 3 );
30+
> var m = accumulator()
31+
null
32+
> m = accumulator( 2.0 )
33+
2.0
34+
> m = accumulator( -5.0 )
35+
-5.0
36+
> m = accumulator( NaN )
37+
-5.0
38+
> m = accumulator( 3.0 )
39+
-5.0
40+
> m = accumulator( 5.0 )
41+
-5.0
42+
> m = accumulator()
43+
-5.0
44+
45+
See Also
46+
--------
47+
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2019 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+
// TypeScript Version: 4.1
20+
21+
/// <reference types="@stdlib/types"/>
22+
23+
/**
24+
* If provided a value, returns an updated minimum value; otherwise, returns the current minimum value.
25+
*
26+
* @param x - value
27+
* @returns minimum value
28+
*/
29+
type accumulator = ( x?: number ) => number | null;
30+
31+
/**
32+
* Returns an accumulator function which incrementally computes a moving minimum value.
33+
*
34+
* ## Notes
35+
*
36+
* - The `W` parameter defines the number of values over which to compute the moving minimum.
37+
* - As `W` values are needed to fill the window buffer, the first `W-1` returned values are calculated from smaller sample sizes. Until the window is full, each returned value is calculated from all provided values.
38+
*
39+
* @param W - window size
40+
* @throws must provide a positive integer
41+
* @returns accumulator function
42+
*
43+
* @example
44+
* var accumulator = incrmmin( 3 );
45+
*
46+
* var m = accumulator();
47+
* // returns null
48+
*
49+
* m = accumulator( 2.0 );
50+
* // returns 2.0
51+
*
52+
* m = accumulator( -5.0 );
53+
* // returns -5.0
54+
*
55+
* m = accumulator( NaN );
56+
* // returns -5.0
57+
*
58+
* m = accumulator( 3.0 );
59+
* // returns -5.0
60+
*
61+
* m = accumulator( 5.0 );
62+
* // returns -5.0
63+
*
64+
* m = accumulator();
65+
* // returns -5.0
66+
*/
67+
declare function incrnanmmin( W: number ): accumulator;
68+
69+
70+
// EXPORTS //
71+
72+
export = incrnanmmin;
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2019 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+
import incrnanmmin = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns an accumulator function...
25+
{
26+
incrnanmmin( 3 ); // $ExpectType accumulator
27+
}
28+
29+
// The compiler throws an error if the function is provided an argument which is not a number...
30+
{
31+
incrnanmmin( '5' ); // $ExpectError
32+
incrnanmmin( true ); // $ExpectError
33+
incrnanmmin( false ); // $ExpectError
34+
incrnanmmin( null ); // $ExpectError
35+
incrnanmmin( undefined ); // $ExpectError
36+
incrnanmmin( [] ); // $ExpectError
37+
incrnanmmin( {} ); // $ExpectError
38+
incrnanmmin( ( x: number ): number => x ); // $ExpectError
39+
}
40+
41+
// The compiler throws an error if the function is provided an invalid number of arguments...
42+
{
43+
incrnanmmin(); // $ExpectError
44+
incrnanmmin( 3, 2 ); // $ExpectError
45+
}
46+
47+
// The function returns an accumulator function which returns an accumulated result...
48+
{
49+
const acc = incrnanmmin( 3 );
50+
51+
acc(); // $ExpectType number | null
52+
acc( 3.14 ); // $ExpectType number | null
53+
}
54+
55+
// The compiler throws an error if the returned accumulator function is provided invalid arguments...
56+
{
57+
const acc = incrnanmmin( 3 );
58+
59+
acc( '5' ); // $ExpectError
60+
acc( true ); // $ExpectError
61+
acc( false ); // $ExpectError
62+
acc( null ); // $ExpectError
63+
acc( [] ); // $ExpectError
64+
acc( {} ); // $ExpectError
65+
acc( ( x: number ): number => x ); // $ExpectError
66+
}

0 commit comments

Comments
 (0)