Socket
Socket
Sign inDemoInstall

d3-array

Package Overview
Dependencies
Maintainers
1
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

d3-array - npm Package Compare versions

Comparing version 1.0.3 to 1.1.0

src/cross.js

27

build/d3-array.js

@@ -1,2 +0,2 @@

// https://d3js.org/d3-array/ Version 1.0.3. Copyright 2017 Mike Bostock.
// https://d3js.org/d3-array/ Version 1.1.0. Copyright 2017 Mike Bostock.
(function (global, factory) {

@@ -48,2 +48,20 @@ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :

var pairs = function(array, f) {
if (f == null) f = pair;
var i = 0, n = array.length - 1, p = array[0], pairs = new Array(n < 0 ? 0 : n);
while (i < n) pairs[i] = f(p, p = array[++i]);
return pairs;
};
function pair(a, b) {
return [a, b];
}
var cross = function(a, b, f) {
var na = a.length, nb = b.length, c = new Array(na * nb), ia, ib, ic, va;
if (f == null) f = pair;
for (ia = ic = 0; ia < na; ++ia) for (va = a[ia], ib = 0; ib < nb; ++ib, ++ic) c[ic] = f(va, b[ib]);
return c;
};
var descending = function(a, b) {

@@ -357,8 +375,2 @@ return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;

var pairs = function(array) {
var i = 0, n = array.length - 1, p = array[0], pairs = new Array(n < 0 ? 0 : n);
while (i < n) pairs[i] = [p, p = array[++i]];
return pairs;
};
var permute = function(array, indexes) {

@@ -440,2 +452,3 @@ var i = indexes.length, permutes = new Array(i);

exports.bisector = bisector;
exports.cross = cross;
exports.descending = descending;

@@ -442,0 +455,0 @@ exports.deviation = deviation;

@@ -1,2 +0,2 @@

// https://d3js.org/d3-array/ Version 1.0.3. Copyright 2017 Mike Bostock.
!function(n,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r(n.d3=n.d3||{})}(this,function(n){"use strict";function r(n){return function(r,t){return u(n(r),t)}}function t(n,r,t){var e=Math.abs(r-n)/Math.max(0,t),u=Math.pow(10,Math.floor(Math.log(e)/Math.LN10)),o=e/u;return o>=m?u*=10:o>=b?u*=5:o>=A&&(u*=2),r<n?-u:u}function e(n){return n.length}var u=function(n,r){return n<r?-1:n>r?1:n>=r?0:NaN},o=function(n){return 1===n.length&&(n=r(n)),{left:function(r,t,e,u){for(null==e&&(e=0),null==u&&(u=r.length);e<u;){var o=e+u>>>1;n(r[o],t)<0?e=o+1:u=o}return e},right:function(r,t,e,u){for(null==e&&(e=0),null==u&&(u=r.length);e<u;){var o=e+u>>>1;n(r[o],t)>0?u=o:e=o+1}return e}}},f=o(u),l=f.right,i=f.left,a=function(n,r){return r<n?-1:r>n?1:r>=n?0:NaN},h=function(n){return null===n?NaN:+n},c=function(n,r){var t,e,u=n.length,o=0,f=0,l=-1,i=0;if(null==r)for(;++l<u;)isNaN(t=h(n[l]))||(e=t-o,o+=e/++i,f+=e*(t-o));else for(;++l<u;)isNaN(t=h(r(n[l],l,n)))||(e=t-o,o+=e/++i,f+=e*(t-o));if(i>1)return f/(i-1)},s=function(n,r){var t=c(n,r);return t?Math.sqrt(t):t},g=function(n,r){var t,e,u,o=-1,f=n.length;if(null==r){for(;++o<f;)if(null!=(e=n[o])&&e>=e){t=u=e;break}for(;++o<f;)null!=(e=n[o])&&(t>e&&(t=e),u<e&&(u=e))}else{for(;++o<f;)if(null!=(e=r(n[o],o,n))&&e>=e){t=u=e;break}for(;++o<f;)null!=(e=r(n[o],o,n))&&(t>e&&(t=e),u<e&&(u=e))}return[t,u]},v=Array.prototype,p=v.slice,d=v.map,M=function(n){return function(){return n}},y=function(n){return n},N=function(n,r,t){n=+n,r=+r,t=(u=arguments.length)<2?(r=n,n=0,1):u<3?1:+t;for(var e=-1,u=0|Math.max(0,Math.ceil((r-n)/t)),o=new Array(u);++e<u;)o[e]=n+e*t;return o},m=Math.sqrt(50),b=Math.sqrt(10),A=Math.sqrt(2),w=function(n,r,e){var u=t(n,r,e);return N(Math.ceil(n/u)*u,Math.floor(r/u)*u+u/2,u)},x=function(n){return Math.ceil(Math.log(n.length)/Math.LN2)+1},k=function(){function n(n){var u,o,f=n.length,i=new Array(f);for(u=0;u<f;++u)i[u]=r(n[u],u,n);var a=t(i),h=a[0],c=a[1],s=e(i,h,c);Array.isArray(s)||(s=w(h,c,s));for(var g=s.length;s[0]<=h;)s.shift(),--g;for(;s[g-1]>=c;)s.pop(),--g;var v,p=new Array(g+1);for(u=0;u<=g;++u)v=p[u]=[],v.x0=u>0?s[u-1]:h,v.x1=u<g?s[u]:c;for(u=0;u<f;++u)o=i[u],h<=o&&o<=c&&p[l(s,o,0,g)].push(n[u]);return p}var r=y,t=g,e=x;return n.value=function(t){return arguments.length?(r="function"==typeof t?t:M(t),n):r},n.domain=function(r){return arguments.length?(t="function"==typeof r?r:M([r[0],r[1]]),n):t},n.thresholds=function(r){return arguments.length?(e="function"==typeof r?r:M(Array.isArray(r)?p.call(r):r),n):e},n},q=function(n,r,t){if(null==t&&(t=h),e=n.length){if((r=+r)<=0||e<2)return+t(n[0],0,n);if(r>=1)return+t(n[e-1],e-1,n);var e,u=(e-1)*r,o=Math.floor(u),f=+t(n[o],o,n);return f+(+t(n[o+1],o+1,n)-f)*(u-o)}},L=function(n,r,t){return n=d.call(n,h).sort(u),Math.ceil((t-r)/(2*(q(n,.75)-q(n,.25))*Math.pow(n.length,-1/3)))},S=function(n,r,t){return Math.ceil((t-r)/(3.5*s(n)*Math.pow(n.length,-1/3)))},j=function(n,r){var t,e,u=-1,o=n.length;if(null==r){for(;++u<o;)if(null!=(e=n[u])&&e>=e){t=e;break}for(;++u<o;)null!=(e=n[u])&&e>t&&(t=e)}else{for(;++u<o;)if(null!=(e=r(n[u],u,n))&&e>=e){t=e;break}for(;++u<o;)null!=(e=r(n[u],u,n))&&e>t&&(t=e)}return t},_=function(n,r){var t,e=0,u=n.length,o=-1,f=u;if(null==r)for(;++o<u;)isNaN(t=h(n[o]))?--f:e+=t;else for(;++o<u;)isNaN(t=h(r(n[o],o,n)))?--f:e+=t;if(f)return e/f},z=function(n,r){var t,e=[],o=n.length,f=-1;if(null==r)for(;++f<o;)isNaN(t=h(n[f]))||e.push(t);else for(;++f<o;)isNaN(t=h(r(n[f],f,n)))||e.push(t);return q(e.sort(u),.5)},D=function(n){for(var r,t,e,u=n.length,o=-1,f=0;++o<u;)f+=n[o].length;for(t=new Array(f);--u>=0;)for(e=n[u],r=e.length;--r>=0;)t[--f]=e[r];return t},F=function(n,r){var t,e,u=-1,o=n.length;if(null==r){for(;++u<o;)if(null!=(e=n[u])&&e>=e){t=e;break}for(;++u<o;)null!=(e=n[u])&&t>e&&(t=e)}else{for(;++u<o;)if(null!=(e=r(n[u],u,n))&&e>=e){t=e;break}for(;++u<o;)null!=(e=r(n[u],u,n))&&t>e&&(t=e)}return t},O=function(n){for(var r=0,t=n.length-1,e=n[0],u=new Array(t<0?0:t);r<t;)u[r]=[e,e=n[++r]];return u},P=function(n,r){for(var t=r.length,e=new Array(t);t--;)e[t]=n[r[t]];return e},R=function(n,r){if(t=n.length){var t,e,o=0,f=0,l=n[f];for(r||(r=u);++o<t;)(r(e=n[o],l)<0||0!==r(l,l))&&(l=e,f=o);return 0===r(l,l)?f:void 0}},B=function(n,r,t){for(var e,u,o=(null==t?n.length:t)-(r=null==r?0:+r);o;)u=Math.random()*o--|0,e=n[o+r],n[o+r]=n[u+r],n[u+r]=e;return n},C=function(n,r){var t,e=0,u=n.length,o=-1;if(null==r)for(;++o<u;)(t=+n[o])&&(e+=t);else for(;++o<u;)(t=+r(n[o],o,n))&&(e+=t);return e},E=function(n){if(!(o=n.length))return[];for(var r=-1,t=F(n,e),u=new Array(t);++r<t;)for(var o,f=-1,l=u[r]=new Array(o);++f<o;)l[f]=n[f][r];return u},G=function(){return E(arguments)};n.bisect=l,n.bisectRight=l,n.bisectLeft=i,n.ascending=u,n.bisector=o,n.descending=a,n.deviation=s,n.extent=g,n.histogram=k,n.thresholdFreedmanDiaconis=L,n.thresholdScott=S,n.thresholdSturges=x,n.max=j,n.mean=_,n.median=z,n.merge=D,n.min=F,n.pairs=O,n.permute=P,n.quantile=q,n.range=N,n.scan=R,n.shuffle=B,n.sum=C,n.ticks=w,n.tickStep=t,n.transpose=E,n.variance=c,n.zip=G,Object.defineProperty(n,"__esModule",{value:!0})});
// https://d3js.org/d3-array/ Version 1.1.0. Copyright 2017 Mike Bostock.
!function(n,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r(n.d3=n.d3||{})}(this,function(n){"use strict";function r(n){return function(r,t){return o(n(r),t)}}function t(n,r){return[n,r]}function e(n,r,t){var e=Math.abs(r-n)/Math.max(0,t),u=Math.pow(10,Math.floor(Math.log(e)/Math.LN10)),o=e/u;return o>=w?u*=10:o>=x?u*=5:o>=k&&(u*=2),r<n?-u:u}function u(n){return n.length}var o=function(n,r){return n<r?-1:n>r?1:n>=r?0:NaN},f=function(n){return 1===n.length&&(n=r(n)),{left:function(r,t,e,u){for(null==e&&(e=0),null==u&&(u=r.length);e<u;){var o=e+u>>>1;n(r[o],t)<0?e=o+1:u=o}return e},right:function(r,t,e,u){for(null==e&&(e=0),null==u&&(u=r.length);e<u;){var o=e+u>>>1;n(r[o],t)>0?u=o:e=o+1}return e}}},l=f(o),i=l.right,a=l.left,h=function(n,r){null==r&&(r=t);for(var e=0,u=n.length-1,o=n[0],f=new Array(u<0?0:u);e<u;)f[e]=r(o,o=n[++e]);return f},c=function(n,r,e){var u,o,f,l,i=n.length,a=r.length,h=new Array(i*a);for(null==e&&(e=t),u=f=0;u<i;++u)for(l=n[u],o=0;o<a;++o,++f)h[f]=e(l,r[o]);return h},s=function(n,r){return r<n?-1:r>n?1:r>=n?0:NaN},g=function(n){return null===n?NaN:+n},v=function(n,r){var t,e,u=n.length,o=0,f=0,l=-1,i=0;if(null==r)for(;++l<u;)isNaN(t=g(n[l]))||(e=t-o,o+=e/++i,f+=e*(t-o));else for(;++l<u;)isNaN(t=g(r(n[l],l,n)))||(e=t-o,o+=e/++i,f+=e*(t-o));if(i>1)return f/(i-1)},p=function(n,r){var t=v(n,r);return t?Math.sqrt(t):t},d=function(n,r){var t,e,u,o=-1,f=n.length;if(null==r){for(;++o<f;)if(null!=(e=n[o])&&e>=e){t=u=e;break}for(;++o<f;)null!=(e=n[o])&&(t>e&&(t=e),u<e&&(u=e))}else{for(;++o<f;)if(null!=(e=r(n[o],o,n))&&e>=e){t=u=e;break}for(;++o<f;)null!=(e=r(n[o],o,n))&&(t>e&&(t=e),u<e&&(u=e))}return[t,u]},M=Array.prototype,y=M.slice,N=M.map,m=function(n){return function(){return n}},A=function(n){return n},b=function(n,r,t){n=+n,r=+r,t=(u=arguments.length)<2?(r=n,n=0,1):u<3?1:+t;for(var e=-1,u=0|Math.max(0,Math.ceil((r-n)/t)),o=new Array(u);++e<u;)o[e]=n+e*t;return o},w=Math.sqrt(50),x=Math.sqrt(10),k=Math.sqrt(2),q=function(n,r,t){var u=e(n,r,t);return b(Math.ceil(n/u)*u,Math.floor(r/u)*u+u/2,u)},L=function(n){return Math.ceil(Math.log(n.length)/Math.LN2)+1},S=function(){function n(n){var u,o,f=n.length,l=new Array(f);for(u=0;u<f;++u)l[u]=r(n[u],u,n);var a=t(l),h=a[0],c=a[1],s=e(l,h,c);Array.isArray(s)||(s=q(h,c,s));for(var g=s.length;s[0]<=h;)s.shift(),--g;for(;s[g-1]>=c;)s.pop(),--g;var v,p=new Array(g+1);for(u=0;u<=g;++u)v=p[u]=[],v.x0=u>0?s[u-1]:h,v.x1=u<g?s[u]:c;for(u=0;u<f;++u)o=l[u],h<=o&&o<=c&&p[i(s,o,0,g)].push(n[u]);return p}var r=A,t=d,e=L;return n.value=function(t){return arguments.length?(r="function"==typeof t?t:m(t),n):r},n.domain=function(r){return arguments.length?(t="function"==typeof r?r:m([r[0],r[1]]),n):t},n.thresholds=function(r){return arguments.length?(e="function"==typeof r?r:m(Array.isArray(r)?y.call(r):r),n):e},n},j=function(n,r,t){if(null==t&&(t=g),e=n.length){if((r=+r)<=0||e<2)return+t(n[0],0,n);if(r>=1)return+t(n[e-1],e-1,n);var e,u=(e-1)*r,o=Math.floor(u),f=+t(n[o],o,n);return f+(+t(n[o+1],o+1,n)-f)*(u-o)}},_=function(n,r,t){return n=N.call(n,g).sort(o),Math.ceil((t-r)/(2*(j(n,.75)-j(n,.25))*Math.pow(n.length,-1/3)))},z=function(n,r,t){return Math.ceil((t-r)/(3.5*p(n)*Math.pow(n.length,-1/3)))},D=function(n,r){var t,e,u=-1,o=n.length;if(null==r){for(;++u<o;)if(null!=(e=n[u])&&e>=e){t=e;break}for(;++u<o;)null!=(e=n[u])&&e>t&&(t=e)}else{for(;++u<o;)if(null!=(e=r(n[u],u,n))&&e>=e){t=e;break}for(;++u<o;)null!=(e=r(n[u],u,n))&&e>t&&(t=e)}return t},F=function(n,r){var t,e=0,u=n.length,o=-1,f=u;if(null==r)for(;++o<u;)isNaN(t=g(n[o]))?--f:e+=t;else for(;++o<u;)isNaN(t=g(r(n[o],o,n)))?--f:e+=t;if(f)return e/f},O=function(n,r){var t,e=[],u=n.length,f=-1;if(null==r)for(;++f<u;)isNaN(t=g(n[f]))||e.push(t);else for(;++f<u;)isNaN(t=g(r(n[f],f,n)))||e.push(t);return j(e.sort(o),.5)},P=function(n){for(var r,t,e,u=n.length,o=-1,f=0;++o<u;)f+=n[o].length;for(t=new Array(f);--u>=0;)for(e=n[u],r=e.length;--r>=0;)t[--f]=e[r];return t},R=function(n,r){var t,e,u=-1,o=n.length;if(null==r){for(;++u<o;)if(null!=(e=n[u])&&e>=e){t=e;break}for(;++u<o;)null!=(e=n[u])&&t>e&&(t=e)}else{for(;++u<o;)if(null!=(e=r(n[u],u,n))&&e>=e){t=e;break}for(;++u<o;)null!=(e=r(n[u],u,n))&&t>e&&(t=e)}return t},B=function(n,r){for(var t=r.length,e=new Array(t);t--;)e[t]=n[r[t]];return e},C=function(n,r){if(t=n.length){var t,e,u=0,f=0,l=n[f];for(r||(r=o);++u<t;)(r(e=n[u],l)<0||0!==r(l,l))&&(l=e,f=u);return 0===r(l,l)?f:void 0}},E=function(n,r,t){for(var e,u,o=(null==t?n.length:t)-(r=null==r?0:+r);o;)u=Math.random()*o--|0,e=n[o+r],n[o+r]=n[u+r],n[u+r]=e;return n},G=function(n,r){var t,e=0,u=n.length,o=-1;if(null==r)for(;++o<u;)(t=+n[o])&&(e+=t);else for(;++o<u;)(t=+r(n[o],o,n))&&(e+=t);return e},H=function(n){if(!(o=n.length))return[];for(var r=-1,t=R(n,u),e=new Array(t);++r<t;)for(var o,f=-1,l=e[r]=new Array(o);++f<o;)l[f]=n[f][r];return e},I=function(){return H(arguments)};n.bisect=i,n.bisectRight=i,n.bisectLeft=a,n.ascending=o,n.bisector=f,n.cross=c,n.descending=s,n.deviation=p,n.extent=d,n.histogram=S,n.thresholdFreedmanDiaconis=_,n.thresholdScott=z,n.thresholdSturges=L,n.max=D,n.mean=F,n.median=O,n.merge=P,n.min=R,n.pairs=h,n.permute=B,n.quantile=j,n.range=b,n.scan=C,n.shuffle=E,n.sum=G,n.ticks=q,n.tickStep=e,n.transpose=H,n.variance=v,n.zip=I,Object.defineProperty(n,"__esModule",{value:!0})});
export {default as bisect, bisectRight, bisectLeft} from "./src/bisect";
export {default as ascending} from "./src/ascending";
export {default as bisector} from "./src/bisector";
export {default as cross} from "./src/cross";
export {default as descending} from "./src/descending";

@@ -5,0 +6,0 @@ export {default as deviation} from "./src/deviation";

{
"name": "d3-array",
"version": "1.0.3",
"version": "1.1.0",
"description": "Array manipulation, ordering, searching, summarizing, etc.",

@@ -5,0 +5,0 @@ "keywords": [

@@ -205,2 +205,19 @@ # d3-array

<a name="cross" href="#cross">#</a> d3.<b>cross</b>(<i>a</i>, <i>b</i>[, <i>reducer</i>]) [<>](https://github.com/d3/d3-array/blob/master/src/cross.js "Source")
Returns the [Cartesian product](https://en.wikipedia.org/wiki/Cartesian_product) of the two arrays *a* and *b*. For each element *i* in the specified array *a* and each element *j* in the specified array *b*, in order, invokes the specified *reducer* function passing the element *i* and element *j*. If a *reducer* is not specified, it defaults to a function which creates a two-element array for each pair:
```js
function pair(a, b) {
return [a, b];
}
```
For example:
```js
d3.cross([1, 2], ["x", "y"]); // returns [[1, "x"], [1, "y"], [2, "x"], [2, "y"]]
d3.cross([1, 2], ["x", "y"], (a, b) => a + b); // returns ["1x", "1y", "2x", "2y"]
```
<a name="merge" href="#merge">#</a> d3.<b>merge</b>(<i>arrays</i>) [<>](https://github.com/d3/d3-array/blob/master/src/merge.js "Source")

@@ -214,8 +231,17 @@

<a name="pairs" href="#pairs">#</a> d3.<b>pairs</b>(<i>array</i>) [<>](https://github.com/d3/d3-array/blob/master/src/pairs.js "Source")
<a name="pairs" href="#pairs">#</a> d3.<b>pairs</b>(<i>array</i>[, <i>reducer</i>]) [<>](https://github.com/d3/d3-array/blob/master/src/pairs.js "Source")
For each adjacent pair of elements in the specified *array*, returns a new array of tuples of element *i* and element *i* - 1. For example:
For each adjacent pair of elements in the specified *array*, in order, invokes the specified *reducer* function passing the element *i* and element *i* - 1. If a *reducer* is not specified, it defaults to a function which creates a two-element array for each pair:
```js
function pair(a, b) {
return [a, b];
}
```
For example:
```js
d3.pairs([1, 2, 3, 4]); // returns [[1, 2], [2, 3], [3, 4]]
d3.pairs([1, 2, 3, 4], (a, b) => b - a); // returns [1, 1, 1];
```

@@ -222,0 +248,0 @@

@@ -1,5 +0,10 @@

export default function(array) {
export default function(array, f) {
if (f == null) f = pair;
var i = 0, n = array.length - 1, p = array[0], pairs = new Array(n < 0 ? 0 : n);
while (i < n) pairs[i] = [p, p = array[++i]];
while (i < n) pairs[i] = f(p, p = array[++i]);
return pairs;
}
export function pair(a, b) {
return [a, b];
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc