Skip to content

Commit 0cccb8c

Browse files
committed
feat: add the TS files
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent 37f1b4d commit 0cccb8c

File tree

2 files changed

+136
-0
lines changed

2 files changed

+136
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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 both arguments, returns an updated weighted standard deviation; otherwise, returns the current weighted standard deviation.
25+
*
26+
* ## Notes
27+
*
28+
* - If provided `NaN` or a value which, when used in computations, results in `NaN`, the accumulated value is `NaN` for all future invocations.
29+
*
30+
* @param x - value
31+
* @param w - weight
32+
* @returns weighted standard deviation
33+
*/
34+
type accumulator = ( x?: number, w?: number ) => number | null;
35+
36+
/**
37+
* Returns an accumulator function which incrementally computes a weighted standard deviation.
38+
*
39+
* @returns accumulator function
40+
*
41+
* @example
42+
* var accumulator = incrwstdev();
43+
*
44+
* var stdev = accumulator();
45+
* // returns null
46+
*
47+
* stdev = accumulator( 2.0, 1.0 );
48+
* // returns 0.0
49+
*
50+
* stdev = accumulator( 3.0, 2.0 );
51+
* // returns ~0.471
52+
*
53+
* stdev = accumulator( 2.0, 0.1 );
54+
* // returns ~0.478
55+
*
56+
* stdev = accumulator();
57+
* // returns ~0.478
58+
*
59+
* @example
60+
* var accumulator = incrwstdev( 3.0 );
61+
*/
62+
declare function incrwstdev(): accumulator;
63+
64+
65+
// EXPORTS //
66+
67+
export = incrwstdev;
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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 incrwstdev = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns an accumulator function...
25+
{
26+
incrwstdev(); // $ExpectType accumulator
27+
}
28+
29+
// The compiler throws an error if the function is provided arguments...
30+
{
31+
incrwstdev( '5' ); // $ExpectError
32+
incrwstdev( 5 ); // $ExpectError
33+
incrwstdev( true ); // $ExpectError
34+
incrwstdev( false ); // $ExpectError
35+
incrwstdev( null ); // $ExpectError
36+
incrwstdev( undefined ); // $ExpectError
37+
incrwstdev( [] ); // $ExpectError
38+
incrwstdev( {} ); // $ExpectError
39+
incrwstdev( ( x: number ): number => x ); // $ExpectError
40+
}
41+
42+
// The function returns an accumulator function which returns an accumulated result...
43+
{
44+
const acc = incrwstdev();
45+
46+
acc(); // $ExpectType number | null
47+
acc( 3.14, 1.0 ); // $ExpectType number | null
48+
}
49+
50+
// The compiler throws an error if the returned accumulator function is provided invalid arguments...
51+
{
52+
const acc = incrwstdev();
53+
54+
acc( '5', 1.0 ); // $ExpectError
55+
acc( true, 1.0 ); // $ExpectError
56+
acc( false, 1.0 ); // $ExpectError
57+
acc( null, 1.0 ); // $ExpectError
58+
acc( [], 1.0 ); // $ExpectError
59+
acc( {}, 1.0 ); // $ExpectError
60+
acc( ( x: number ): number => x, 1.0 ); // $ExpectError
61+
62+
acc( 3.14, '5' ); // $ExpectError
63+
acc( 3.14, true ); // $ExpectError
64+
acc( 3.14, false ); // $ExpectError
65+
acc( 3.14, null ); // $ExpectError
66+
acc( 3.14, [] ); // $ExpectError
67+
acc( 3.14, {} ); // $ExpectError
68+
acc( 3.14, ( x: number ): number => x ); // $ExpectError
69+
}

0 commit comments

Comments
 (0)