Skip to content

Commit d4d2f01

Browse files
committed
solving eslint issue in README.js
1 parent 7b2f242 commit d4d2f01

File tree

2 files changed

+46
-32
lines changed

2 files changed

+46
-32
lines changed

lib/node_modules/@stdlib/stats/incr/nanmvariance/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@ s2 = accumulator( -5.0 ); // [2.0, NaN, -5.0]
6969

7070
// Window begins sliding...
7171
s2 = accumulator( 3.0 ); // [NaN, -5.0, 3.0]
72-
// returns 32.0
72+
// returns 19.0
7373

7474
s2 = accumulator( NaN ); // [-5.0, 3.0, NaN]
75-
// returns 32.0
75+
// returns 19.0
7676

7777
s2 = accumulator();
78-
// returns 32.0
78+
// returns 19.0
7979
```
8080

8181
</section>

lib/node_modules/@stdlib/stats/incr/nanmvariance/lib/main.js

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ function incrnanmvariance( W, mean ) {
8080
throw new TypeError( format( 'invalid argument. Must provide a positive integer. Value: `%s`.', W ) );
8181
}
8282

83-
buf = new Array( W );
83+
buf = [];
8484
n = W - 1;
8585
M2 = 0.0;
8686
i = -1;
@@ -105,9 +105,6 @@ function incrnanmvariance( W, mean ) {
105105
* @returns {(number|null)} unbiased sample variance or null
106106
*/
107107
function accumulator1( x ) {
108-
var k;
109-
var v;
110-
111108
if ( arguments.length === 0 ) {
112109
if ( N === 0 ) {
113110
return null;
@@ -116,60 +113,72 @@ function incrnanmvariance( W, mean ) {
116113
return 0.0;
117114
}
118115
if ( N < W ) {
119-
return M2 / (N-1);
116+
return M2 / ( N - 1 );
120117
}
121118
return M2 / n;
122119
}
123120

124-
// If incoming value is NaN, ignore it:
125121
if ( isnan( x ) ) {
126-
return ( N === 0 ) ? null : ( N === 1 ) ? 0.0 : ( N < W ) ? M2 / (N-1) : M2 / n;
122+
if ( N === 0 ) {
123+
return null;
124+
}
125+
if ( N === 1 ) {
126+
return 0.0;
127+
}
128+
if ( N < W ) {
129+
return M2 / ( N - 1 );
130+
}
131+
return M2 / n;
127132
}
128133

134+
129135
// Update the index for managing the circular buffer:
130-
i = (i+1) % W;
136+
i = ( i+1 ) % W;
131137

132138
// Case: initial window...
133139
if ( N < W ) {
134-
buf[ i ] = x; // update buffer
140+
if ( N < W ) {
141+
buf.push( x );
142+
} else {
143+
buf[ i ] = x;
144+
}
135145
N += 1;
136146
delta = x - mu;
137147
mu += delta / N;
138-
M2 += delta * (x - mu);
148+
M2 += delta * ( x - mu );
139149
if ( N === 1 ) {
140150
return 0.0;
141151
}
142-
return M2 / (N-1);
152+
return M2 / ( N-1 );
143153
}
144154

145155
// Case: N = W = 1
146-
else if ( N === 1 ) {
156+
if (N === 1) {
147157
M2 = 0.0;
148158
return M2;
149159
}
150160

151161
// Case: outgoing value is NaN, which we need to simply replace without affecting the variance
152-
else if ( isnan( buf[ i ] ) ) {
153-
buf[ i ] = x;
154-
// When replacing NaN with a value, we need to update M2 with the squared difference from mean
162+
if (isnan(buf[i])) {
163+
buf[i] = x;
164+
165+
// When replacing NaN with a value, update M2 with the squared difference from the mean
155166
M2 += (x - mu) * (x - mu);
156167
return M2 / n;
157168
}
158169

159170
// Case: standard update when neither incoming nor outgoing values are NaN
160-
else {
161-
tmp = buf[ i ];
162-
delta = x - tmp;
163-
d1 = tmp - mu;
164-
mu += delta / N;
165-
d2 = x - mu;
166-
M2 += delta * (d1 + d2);
167-
}
168-
169-
buf[ i ] = x;
171+
tmp = buf[i];
172+
delta = x - tmp;
173+
d1 = tmp - mu;
174+
mu += delta / N;
175+
d2 = x - mu;
176+
M2 += delta * (d1 + d2);
177+
178+
buf[i] = x;
170179
return M2 / n;
171180
}
172-
181+
173182
/**
174183
* If provided a value, the accumulator function returns an updated unbiased sample variance, ignoring NaN values. If not provided a value, the accumulator function returns the current unbiased sample variance.
175184
*
@@ -178,8 +187,6 @@ function incrnanmvariance( W, mean ) {
178187
* @returns {(number|null)} unbiased sample variance or null
179188
*/
180189
function accumulator2( x ) {
181-
var k;
182-
183190
if ( arguments.length === 0 ) {
184191
if ( N === 0 ) {
185192
return null;
@@ -200,7 +207,11 @@ function incrnanmvariance( W, mean ) {
200207

201208
// Case: initial window...
202209
if ( N < W ) {
203-
buf[ i ] = x; // update buffer
210+
if ( N < W ) {
211+
buf.push( x );
212+
} else {
213+
buf[ i ] = x;
214+
}
204215
N += 1;
205216
delta = x - mu;
206217
M2 += delta * delta;
@@ -210,6 +221,7 @@ function incrnanmvariance( W, mean ) {
210221
// Case: outgoing value is NaN, which we need to simply replace without affecting the variance
211222
else if ( isnan( buf[ i ] ) ) {
212223
buf[ i ] = x;
224+
213225
// Add the squared difference between the new value and mean
214226
M2 += (x - mu) * (x - mu);
215227
return M2 / W;
@@ -218,8 +230,10 @@ function incrnanmvariance( W, mean ) {
218230
// Case: standard update when neither incoming nor outgoing values are NaN
219231
else {
220232
tmp = buf[ i ];
233+
221234
// Remove the contribution of the outgoing value
222235
M2 -= (tmp - mu) * (tmp - mu);
236+
223237
// Add the contribution of the incoming value
224238
M2 += (x - mu) * (x - mu);
225239
}

0 commit comments

Comments
 (0)