@stdlib/esm
Version:
ES module distribution for Stdlib, a standard library for JavaScript and Node.js.
3 lines • 2.45 kB
JavaScript
// 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-collection.js";import e from"./../assert/contains.js";import n from"./../assert/is-array.js";import t from"./../assert/is-object.js";import i from"./../assert/is-string.js";import o from"./../assert/has-own-property.js";function s(r){var e,n,t;for(e=r.length,n=0,t=0;t<e;t++)n+=r[t];return n}function a(r,e){return r<e?-1:r>e?1:0}function m(r){var e,n;for(e=new Array(r.length),n=0;n<r.length;n++)e[n]=n;return e.sort((function(e,n){return a(r[e],r[n])}))}var l=e;function f(r,e){var n,t,i;for(n=r.length,t=new Array(n),i=0;i<n;i++)t[i]=l(e,r[i]);return t}var g=e,u=n,h=t,d=i.isPrimitive,c=o,p=["min","max","average","dense","ordinal"],v=["last","first","remove"];function w(r,e){return h(e)?c(e,"encoding")&&(r.encoding=e.encoding,!u(r.encoding))?new TypeError("invalid option. `encoding` option must be an array. Option: `"+r.encoding+"`."):!c(e,"method")||(r.method=e.method,d(r.method)&&g(p,r.method))?!c(e,"missing")||(r.missing=e.missing,d(r.missing)&&g(v,r.missing))?null:new TypeError("invalid option. `missing` must be one of the following values: `last`, `first`, or `remove`. Option: `"+r.missing+"`."):new TypeError("invalid option. `method` must be one of the following values: `average`, `min`, `max`, `dense`, or `ordinal`. Option: `"+r.method+"`."):new TypeError("invalid argument. Options argument must be an object. Value: `"+e+"`.")}var y=r,b=e,j=s,x=m,A=f,E=w;function T(r,e){var n,t,i,o,s,a,m,l,f,g,u,h,d,c,p,v,w,T;if(!y(r))throw new TypeError("invalid argument. First argument `x` must be an array-like object. Value: `"+r+"`.");if(d={},arguments.length>1&&(p=E(d,e)))throw p;for(u=d.method||"average",a=d.encoding||[null,NaN],f=d.missing||"last",v=r.length,c=[],w=0;w<v;w++)b(a,r[w])||c.push(r[w]);if(n=A(r,a),v=c.length,o=0,h=new Array(v),l=x(c),"ordinal"===u)for(w=0;w<v;w++)h[l[w]]=w+1;else for(t=0,w=0;w<v;w++)if(m=w+1,w===v-1||c[l[w]]!==c[l[m]]){switch(u){case"average":default:g=m-.5*t;break;case"min":g=m-t;break;case"max":g=m;break;case"dense":g=m-t-o,o+=t}for(T=w-t;T<m;T++)h[l[T]]=g;t=0}else t+=1;if("first"===f){for(i=j(n),T=1,s=new Array(n.length),w=0;w<n.length;w++)n[w]?(s[w]=T,T+=1):s[w]=h.shift()+i;return s}if("last"===f){for(s=new Array(n.length),w=0;w<n.length;w++)n[w]?s[w]=w+h.length+1:s[w]=h.shift();return s}return h}var k=T;export default k;
//# sourceMappingURL=ranks.js.map