UNPKG

@stdlib/esm

Version:

ES module distribution for Stdlib, a standard library for JavaScript and Node.js.

3 lines 1.36 kB
// This file is a part of stdlib. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 import r from"./../../assert/is-positive-integer.js";import e from"./../../assert/is-number.js";import i from"./../../math/base/assert/is-nan.js";var t=r.isPrimitive,n=e.isPrimitive,a=i;function f(r,e){var i,f,s,u,o,l,m,v;if(!t(r))throw new TypeError("invalid argument. Must provide a positive integer. Value: `"+r+"`.");if(f=new Array(r),m=r-1,u=0,v=-1,l=0,arguments.length>1){if(!n(e))throw new TypeError("invalid argument. Must provide a number primitive. Value: `"+e+"`.");return o=e,N}return o=0,p;function p(e){var t,n;if(0===arguments.length)return 0===l?null:1===l?a(u)?NaN:0:l<r?u/(l-1):u/m;if(v=(v+1)%r,a(e))l=r,u=NaN;else{if(l<r)return f[v]=e,u+=(i=e-o)*(e-(o+=i/(l+=1))),1===l?0:u/(l-1);if(1===l)return u=0;if(a(f[v])){for(l=1,o=e,u=0,t=0;t<r;t++)if(t!==v){if(n=f[t],a(n)){l=r,u=NaN;break}u+=(i=n-o)*(n-(o+=i/(l+=1)))}}else!1===a(u)&&(s=f[v],u+=(i=e-s)*(s-o+(e-(o+=i/r))))}return f[v]=e,u/m}function N(e){var t;if(0===arguments.length)return 0===l?null:l<r?u/l:u/r;if(v=(v+1)%r,a(e))l=r,u=NaN;else{if(l<r)return f[v]=e,(u+=(i=e-o)*i)/(l+=1);if(a(f[v])){for(u=0,t=0;t<r;t++)if(t!==v){if(a(f[t])){l=r,u=NaN;break}i=f[t]-o,u+=i*i}}else!1===a(u)&&(s=f[v],u+=(e-s)*(e-o+s-o))}return f[v]=e,u/r}}var s=f;export default s; //# sourceMappingURL=mvariance.js.map