Socket
Socket
Sign inDemoInstall

d3-array

Package Overview
Dependencies
0
Maintainers
1
Versions
61
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.6.0 to 0.6.1

2

build/bundle.js

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

var version = "0.6.0"; export * from "../index"; export {version};
var version = "0.6.1"; export * from "../index"; export {version};

@@ -652,3 +652,3 @@ (function (global, factory) {

var version = "0.6.0";
var version = "0.6.1";

@@ -655,0 +655,0 @@ exports.version = version;

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

!function(n,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define("d3-array",["exports"],r):r(n.d3_array={})}(this,function(n){"use strict";function r(n,r){return r>n?-1:n>r?1:n>=r?0:NaN}function t(n){return 1===n.length&&(n=e(n)),{left:function(r,t,e,u){for(arguments.length<3&&(e=0),arguments.length<4&&(u=r.length);u>e;){var i=e+u>>>1;n(r[i],t)<0?e=i+1:u=i}return e},right:function(r,t,e,u){for(arguments.length<3&&(e=0),arguments.length<4&&(u=r.length);u>e;){var i=e+u>>>1;n(r[i],t)>0?u=i:e=i+1}return e}}}function e(n){return function(t,e){return r(n(t),e)}}function u(n,r){return n>r?-1:r>n?1:r>=n?0:NaN}function i(n){return null===n?NaN:+n}function o(n,r){var t,e,u=n.length,o=0,a=0,f=-1,s=0;if(1===arguments.length)for(;++f<u;)isNaN(t=i(n[f]))||(e=t-o,o+=e/++s,a+=e*(t-o));else for(;++f<u;)isNaN(t=i(r(n[f],f,n)))||(e=t-o,o+=e/++s,a+=e*(t-o));return s>1?a/(s-1):void 0}function a(){var n=o.apply(this,arguments);return n?Math.sqrt(n):n}function f(n){var r=[];for(var t in n)r.push({key:t,value:n[t]});return r}function s(n,r){var t,e,u,i=-1,o=n.length;if(1===arguments.length){for(;++i<o;)if(null!=(e=n[i])&&e>=e){t=u=e;break}for(;++i<o;)null!=(e=n[i])&&(t>e&&(t=e),e>u&&(u=e))}else{for(;++i<o;)if(null!=(e=r(n[i],i,n))&&e>=e){t=u=e;break}for(;++i<o;)null!=(e=r(n[i],i,n))&&(t>e&&(t=e),e>u&&(u=e))}return[t,u]}function h(n){return function(){return n}}function l(n){return n}function c(n,r,t){(u=arguments.length)<3&&(t=1,2>u&&(r=n,n=0));for(var e=-1,u=0|Math.max(0,Math.ceil((r-n)/t)),i=new Array(u);++e<u;)i[e]=n+e*t;return i}function g(n,r,t){var e=v(n,r,t);return c(Math.ceil(n/e)*e,Math.floor(r/e)*e+e/2,e)}function v(n,r,t){var e=Math.abs(r-n)/Math.max(0,t),u=Math.pow(10,Math.floor(Math.log(e)/Math.LN10)),i=e/u;return i>=T?u*=10:i>=U?u*=5:i>=W&&(u*=2),n>r?-u:u}function p(n){return Math.ceil(Math.log(n.length)/Math.LN2)+1}function m(n){return+n}function y(){function n(n){var u,i,o=n.length,a=new Array(o);for(u=0;o>u;++u)a[u]=+r(n[u],u,n);var f=t(a),s=+f[0],h=+f[1],l=e(a,s,h);Array.isArray(l)||(l=g(s,h,+l));var c=l.length;for(u=0;c>u;++u)l[u]=+l[u];for(;l[0]<=s;)l.shift(),--c;for(;l[c-1]>=h;)l.pop(),--c;var v,p=new Array(c+1);for(u=0;c>=u;++u)v=p[u]=[],v.x0=u>0?l[u-1]:s,v.x1=c>u?l[u]:h;for(u=0;o>u;++u)i=a[u],i>=s&&h>=i&&p[P(l,i,0,c)].push(n[u]);return p}var r=l,t=s,e=p;return n.value=function(t){return arguments.length?(r="function"==typeof t?t:h(+t),n):r},n.domain=function(r){return arguments.length?(t="function"==typeof r?r:h([+r[0],+r[1]]),n):t},n.thresholds=function(r){return arguments.length?(e="function"==typeof r?r:h(Array.isArray(r)?Array.prototype.map.call(r,m):+r),n):e},n}function d(n,r,t){if(arguments.length<3&&(t=i),e=n.length){if((r=+r)<=0||2>e)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),a=+t(n[o],o,n),f=+t(n[o+1],o+1,n);return a+(f-a)*(u-o)}}function N(n,t,e){return n.sort(r),Math.ceil((e-t)/(2*(d(n,.75)-d(n,.25))*Math.pow(n.length,-1/3)))}function M(n,r,t){return Math.ceil((t-r)/(3.5*a(n)*Math.pow(n.length,-1/3)))}function k(n){var r=[];for(var t in n)r.push(t);return r}function A(){}function b(n,r){var t=new A;if(n instanceof A)n.each(function(n,r){t.set(r,n)});else if(Array.isArray(n)){var e,u=-1,i=n.length;if(1===arguments.length)for(;++u<i;)t.set(u,n[u]);else for(;++u<i;)t.set(r(e=n[u],u,n),e)}else if(n)for(var o in n)t.set(o,n[o]);return t}function w(n,r){var t,e,u=-1,i=n.length;if(1===arguments.length){for(;++u<i;)if(null!=(e=n[u])&&e>=e){t=e;break}for(;++u<i;)null!=(e=n[u])&&e>t&&(t=e)}else{for(;++u<i;)if(null!=(e=r(n[u],u,n))&&e>=e){t=e;break}for(;++u<i;)null!=(e=r(n[u],u,n))&&e>t&&(t=e)}return t}function x(n,r){var t,e=0,u=n.length,o=-1,a=u;if(1===arguments.length)for(;++o<u;)isNaN(t=i(n[o]))?--a:e+=t;else for(;++o<u;)isNaN(t=i(r(n[o],o,n)))?--a:e+=t;return a?e/a:void 0}function q(n,t){var e,u=[],o=n.length,a=-1;if(1===arguments.length)for(;++a<o;)isNaN(e=i(n[a]))||u.push(e);else for(;++a<o;)isNaN(e=i(t(n[a],a,n)))||u.push(e);return d(u.sort(r),.5)}function z(n){for(var r,t,e,u=n.length,i=-1,o=0;++i<u;)o+=n[i].length;for(t=new Array(o);--u>=0;)for(e=n[u],r=e.length;--r>=0;)t[--o]=e[r];return t}function L(n,r){var t,e,u=-1,i=n.length;if(1===arguments.length){for(;++u<i;)if(null!=(e=n[u])&&e>=e){t=e;break}for(;++u<i;)null!=(e=n[u])&&t>e&&(t=e)}else{for(;++u<i;)if(null!=(e=r(n[u],u,n))&&e>=e){t=e;break}for(;++u<i;)null!=(e=r(n[u],u,n))&&t>e&&(t=e)}return t}function S(){function n(r,u,o,a){if(u>=i.length)return e?e(r):t?r.sort(t):r;for(var f,s,h,l=-1,c=r.length,g=i[u++],v=b(),p=o();++l<c;)(h=v.get(f=g(s=r[l])+""))?h.push(s):v.set(f,[s]);return v.each(function(r,t){a(p,t,n(r,u,o,a))}),p}function r(n,t){if(t>=i.length)return n;var e=[],u=o[t++];return n.each(function(n,u){e.push({key:u,values:r(n,t)})}),u?e.sort(function(n,r){return u(n.key,r.key)}):e}var t,e,u,i=[],o=[];return u={object:function(r){return n(r,0,j,D)},map:function(r){return n(r,0,F,K)},entries:function(t){return r(n(t,0,F,K),0)},key:function(n){return i.push(n),u},sortKeys:function(n){return o[i.length-1]=n,u},sortValues:function(n){return t=n,u},rollup:function(n){return e=n,u}}}function j(){return{}}function D(n,r,t){n[r]=t}function F(){return b()}function K(n,r,t){n.set(r,t)}function R(n){for(var r,t=0,e=n.length-1,u=n[0],i=new Array(0>e?0:e);e>t;)i[t]=[r=u,u=n[++t]];return i}function V(n,r){for(var t=r.length,e=new Array(t);t--;)e[t]=n[r[t]];return e}function $(n,t){if(e=n.length){var e,u,i=0,o=0,a=n[o];for(t||(t=r);++i<e;)(t(u=n[i],a)<0||0!==t(a,a))&&(a=u,o=i);return 0===t(a,a)?o:void 0}}function _(){}function B(n,r){var t=new _;if(n instanceof _)n.each(function(n){t.add(n)});else if(n){var e,u=-1,i=n.length;if(1===arguments.length)for(;++u<i;)t.add(n[u]);else for(;++u<i;)t.add(r(e=n[u],u,n))}return t}function C(n,r,t){(i=arguments.length)<3&&(t=n.length,2>i&&(r=0));for(var e,u,i=t-r;i;)u=Math.random()*i--|0,e=n[i+r],n[i+r]=n[u+r],n[u+r]=e;return n}function E(n,r){var t,e=0,u=n.length,i=-1;if(1===arguments.length)for(;++i<u;)isNaN(t=+n[i])||(e+=t);else for(;++i<u;)isNaN(t=+r(n[i],i,n))||(e+=t);return e}function G(n){if(!(u=n.length))return[];for(var r=-1,t=L(n,H),e=new Array(t);++r<t;)for(var u,i=-1,o=e[r]=new Array(u);++i<u;)o[i]=n[i][r];return e}function H(n){return n.length}function I(n){var r=[];for(var t in n)r.push(n[t]);return r}function J(){return G(arguments)}var O=t(r),P=O.right,Q=O.left,T=Math.sqrt(50),U=Math.sqrt(10),W=Math.sqrt(2),X="$";A.prototype=b.prototype={has:function(n){return X+n in this},get:function(n){return this[X+n]},set:function(n,r){return this[X+n]=r,this},remove:function(n){var r=X+n;return r in this&&delete this[r]},clear:function(){for(var n in this)n[0]===X&&delete this[n]},keys:function(){var n=[];for(var r in this)r[0]===X&&n.push(r.slice(1));return n},values:function(){var n=[];for(var r in this)r[0]===X&&n.push(this[r]);return n},entries:function(){var n=[];for(var r in this)r[0]===X&&n.push({key:r.slice(1),value:this[r]});return n},size:function(){var n=0;for(var r in this)r[0]===X&&++n;return n},empty:function(){for(var n in this)if(n[0]===X)return!1;return!0},each:function(n){for(var r in this)r[0]===X&&n(this[r],r.slice(1),this)}};var Y=b.prototype;_.prototype=B.prototype={has:Y.has,add:function(n){return n+="",this[X+n]=n,this},remove:Y.remove,clear:Y.clear,values:Y.keys,size:Y.size,empty:Y.empty,each:Y.each};var Z="0.6.0";n.version=Z,n.bisect=P,n.bisectRight=P,n.bisectLeft=Q,n.ascending=r,n.bisector=t,n.descending=u,n.deviation=a,n.entries=f,n.extent=s,n.histogram=y,n.thresholdFreedmanDiaconis=N,n.thresholdScott=M,n.thresholdSturges=p,n.keys=k,n.map=b,n.max=w,n.mean=x,n.median=q,n.merge=z,n.min=L,n.nest=S,n.pairs=R,n.permute=V,n.quantile=d,n.range=c,n.scan=$,n.set=B,n.shuffle=C,n.sum=E,n.ticks=g,n.tickStep=v,n.transpose=G,n.values=I,n.variance=o,n.zip=J});
!function(n,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define("d3-array",["exports"],r):r(n.d3_array={})}(this,function(n){"use strict";function r(n,r){return r>n?-1:n>r?1:n>=r?0:NaN}function t(n){return 1===n.length&&(n=e(n)),{left:function(r,t,e,u){for(arguments.length<3&&(e=0),arguments.length<4&&(u=r.length);u>e;){var i=e+u>>>1;n(r[i],t)<0?e=i+1:u=i}return e},right:function(r,t,e,u){for(arguments.length<3&&(e=0),arguments.length<4&&(u=r.length);u>e;){var i=e+u>>>1;n(r[i],t)>0?u=i:e=i+1}return e}}}function e(n){return function(t,e){return r(n(t),e)}}function u(n,r){return n>r?-1:r>n?1:r>=n?0:NaN}function i(n){return null===n?NaN:+n}function o(n,r){var t,e,u=n.length,o=0,a=0,f=-1,s=0;if(1===arguments.length)for(;++f<u;)isNaN(t=i(n[f]))||(e=t-o,o+=e/++s,a+=e*(t-o));else for(;++f<u;)isNaN(t=i(r(n[f],f,n)))||(e=t-o,o+=e/++s,a+=e*(t-o));return s>1?a/(s-1):void 0}function a(){var n=o.apply(this,arguments);return n?Math.sqrt(n):n}function f(n){var r=[];for(var t in n)r.push({key:t,value:n[t]});return r}function s(n,r){var t,e,u,i=-1,o=n.length;if(1===arguments.length){for(;++i<o;)if(null!=(e=n[i])&&e>=e){t=u=e;break}for(;++i<o;)null!=(e=n[i])&&(t>e&&(t=e),e>u&&(u=e))}else{for(;++i<o;)if(null!=(e=r(n[i],i,n))&&e>=e){t=u=e;break}for(;++i<o;)null!=(e=r(n[i],i,n))&&(t>e&&(t=e),e>u&&(u=e))}return[t,u]}function h(n){return function(){return n}}function l(n){return n}function c(n,r,t){(u=arguments.length)<3&&(t=1,2>u&&(r=n,n=0));for(var e=-1,u=0|Math.max(0,Math.ceil((r-n)/t)),i=new Array(u);++e<u;)i[e]=n+e*t;return i}function g(n,r,t){var e=v(n,r,t);return c(Math.ceil(n/e)*e,Math.floor(r/e)*e+e/2,e)}function v(n,r,t){var e=Math.abs(r-n)/Math.max(0,t),u=Math.pow(10,Math.floor(Math.log(e)/Math.LN10)),i=e/u;return i>=T?u*=10:i>=U?u*=5:i>=W&&(u*=2),n>r?-u:u}function p(n){return Math.ceil(Math.log(n.length)/Math.LN2)+1}function m(n){return+n}function y(){function n(n){var u,i,o=n.length,a=new Array(o);for(u=0;o>u;++u)a[u]=+r(n[u],u,n);var f=t(a),s=+f[0],h=+f[1],l=e(a,s,h);Array.isArray(l)||(l=g(s,h,+l));var c=l.length;for(u=0;c>u;++u)l[u]=+l[u];for(;l[0]<=s;)l.shift(),--c;for(;l[c-1]>=h;)l.pop(),--c;var v,p=new Array(c+1);for(u=0;c>=u;++u)v=p[u]=[],v.x0=u>0?l[u-1]:s,v.x1=c>u?l[u]:h;for(u=0;o>u;++u)i=a[u],i>=s&&h>=i&&p[P(l,i,0,c)].push(n[u]);return p}var r=l,t=s,e=p;return n.value=function(t){return arguments.length?(r="function"==typeof t?t:h(+t),n):r},n.domain=function(r){return arguments.length?(t="function"==typeof r?r:h([+r[0],+r[1]]),n):t},n.thresholds=function(r){return arguments.length?(e="function"==typeof r?r:h(Array.isArray(r)?Array.prototype.map.call(r,m):+r),n):e},n}function d(n,r,t){if(arguments.length<3&&(t=i),e=n.length){if((r=+r)<=0||2>e)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),a=+t(n[o],o,n),f=+t(n[o+1],o+1,n);return a+(f-a)*(u-o)}}function N(n,t,e){return n.sort(r),Math.ceil((e-t)/(2*(d(n,.75)-d(n,.25))*Math.pow(n.length,-1/3)))}function M(n,r,t){return Math.ceil((t-r)/(3.5*a(n)*Math.pow(n.length,-1/3)))}function k(n){var r=[];for(var t in n)r.push(t);return r}function A(){}function b(n,r){var t=new A;if(n instanceof A)n.each(function(n,r){t.set(r,n)});else if(Array.isArray(n)){var e,u=-1,i=n.length;if(1===arguments.length)for(;++u<i;)t.set(u,n[u]);else for(;++u<i;)t.set(r(e=n[u],u,n),e)}else if(n)for(var o in n)t.set(o,n[o]);return t}function w(n,r){var t,e,u=-1,i=n.length;if(1===arguments.length){for(;++u<i;)if(null!=(e=n[u])&&e>=e){t=e;break}for(;++u<i;)null!=(e=n[u])&&e>t&&(t=e)}else{for(;++u<i;)if(null!=(e=r(n[u],u,n))&&e>=e){t=e;break}for(;++u<i;)null!=(e=r(n[u],u,n))&&e>t&&(t=e)}return t}function x(n,r){var t,e=0,u=n.length,o=-1,a=u;if(1===arguments.length)for(;++o<u;)isNaN(t=i(n[o]))?--a:e+=t;else for(;++o<u;)isNaN(t=i(r(n[o],o,n)))?--a:e+=t;return a?e/a:void 0}function q(n,t){var e,u=[],o=n.length,a=-1;if(1===arguments.length)for(;++a<o;)isNaN(e=i(n[a]))||u.push(e);else for(;++a<o;)isNaN(e=i(t(n[a],a,n)))||u.push(e);return d(u.sort(r),.5)}function z(n){for(var r,t,e,u=n.length,i=-1,o=0;++i<u;)o+=n[i].length;for(t=new Array(o);--u>=0;)for(e=n[u],r=e.length;--r>=0;)t[--o]=e[r];return t}function L(n,r){var t,e,u=-1,i=n.length;if(1===arguments.length){for(;++u<i;)if(null!=(e=n[u])&&e>=e){t=e;break}for(;++u<i;)null!=(e=n[u])&&t>e&&(t=e)}else{for(;++u<i;)if(null!=(e=r(n[u],u,n))&&e>=e){t=e;break}for(;++u<i;)null!=(e=r(n[u],u,n))&&t>e&&(t=e)}return t}function S(){function n(r,u,o,a){if(u>=i.length)return e?e(r):t?r.sort(t):r;for(var f,s,h,l=-1,c=r.length,g=i[u++],v=b(),p=o();++l<c;)(h=v.get(f=g(s=r[l])+""))?h.push(s):v.set(f,[s]);return v.each(function(r,t){a(p,t,n(r,u,o,a))}),p}function r(n,t){if(t>=i.length)return n;var e=[],u=o[t++];return n.each(function(n,u){e.push({key:u,values:r(n,t)})}),u?e.sort(function(n,r){return u(n.key,r.key)}):e}var t,e,u,i=[],o=[];return u={object:function(r){return n(r,0,j,D)},map:function(r){return n(r,0,F,K)},entries:function(t){return r(n(t,0,F,K),0)},key:function(n){return i.push(n),u},sortKeys:function(n){return o[i.length-1]=n,u},sortValues:function(n){return t=n,u},rollup:function(n){return e=n,u}}}function j(){return{}}function D(n,r,t){n[r]=t}function F(){return b()}function K(n,r,t){n.set(r,t)}function R(n){for(var r,t=0,e=n.length-1,u=n[0],i=new Array(0>e?0:e);e>t;)i[t]=[r=u,u=n[++t]];return i}function V(n,r){for(var t=r.length,e=new Array(t);t--;)e[t]=n[r[t]];return e}function $(n,t){if(e=n.length){var e,u,i=0,o=0,a=n[o];for(t||(t=r);++i<e;)(t(u=n[i],a)<0||0!==t(a,a))&&(a=u,o=i);return 0===t(a,a)?o:void 0}}function _(){}function B(n,r){var t=new _;if(n instanceof _)n.each(function(n){t.add(n)});else if(n){var e,u=-1,i=n.length;if(1===arguments.length)for(;++u<i;)t.add(n[u]);else for(;++u<i;)t.add(r(e=n[u],u,n))}return t}function C(n,r,t){(i=arguments.length)<3&&(t=n.length,2>i&&(r=0));for(var e,u,i=t-r;i;)u=Math.random()*i--|0,e=n[i+r],n[i+r]=n[u+r],n[u+r]=e;return n}function E(n,r){var t,e=0,u=n.length,i=-1;if(1===arguments.length)for(;++i<u;)isNaN(t=+n[i])||(e+=t);else for(;++i<u;)isNaN(t=+r(n[i],i,n))||(e+=t);return e}function G(n){if(!(u=n.length))return[];for(var r=-1,t=L(n,H),e=new Array(t);++r<t;)for(var u,i=-1,o=e[r]=new Array(u);++i<u;)o[i]=n[i][r];return e}function H(n){return n.length}function I(n){var r=[];for(var t in n)r.push(n[t]);return r}function J(){return G(arguments)}var O=t(r),P=O.right,Q=O.left,T=Math.sqrt(50),U=Math.sqrt(10),W=Math.sqrt(2),X="$";A.prototype=b.prototype={has:function(n){return X+n in this},get:function(n){return this[X+n]},set:function(n,r){return this[X+n]=r,this},remove:function(n){var r=X+n;return r in this&&delete this[r]},clear:function(){for(var n in this)n[0]===X&&delete this[n]},keys:function(){var n=[];for(var r in this)r[0]===X&&n.push(r.slice(1));return n},values:function(){var n=[];for(var r in this)r[0]===X&&n.push(this[r]);return n},entries:function(){var n=[];for(var r in this)r[0]===X&&n.push({key:r.slice(1),value:this[r]});return n},size:function(){var n=0;for(var r in this)r[0]===X&&++n;return n},empty:function(){for(var n in this)if(n[0]===X)return!1;return!0},each:function(n){for(var r in this)r[0]===X&&n(this[r],r.slice(1),this)}};var Y=b.prototype;_.prototype=B.prototype={has:Y.has,add:function(n){return n+="",this[X+n]=n,this},remove:Y.remove,clear:Y.clear,values:Y.keys,size:Y.size,empty:Y.empty,each:Y.each};var Z="0.6.1";n.version=Z,n.bisect=P,n.bisectRight=P,n.bisectLeft=Q,n.ascending=r,n.bisector=t,n.descending=u,n.deviation=a,n.entries=f,n.extent=s,n.histogram=y,n.thresholdFreedmanDiaconis=N,n.thresholdScott=M,n.thresholdSturges=p,n.keys=k,n.map=b,n.max=w,n.mean=x,n.median=q,n.merge=z,n.min=L,n.nest=S,n.pairs=R,n.permute=V,n.quantile=d,n.range=c,n.scan=$,n.set=B,n.shuffle=C,n.sum=E,n.ticks=g,n.tickStep=v,n.transpose=G,n.values=I,n.variance=o,n.zip=J});
{
"name": "d3-array",
"version": "0.6.0",
"version": "0.6.1",
"description": "Array manipulation, ordering, searching, summarizing, etc.",

@@ -8,4 +8,8 @@ "keywords": [

"nest",
"histogram",
"bisect",
"shuffle",
"statistics",
"search",
"sort",
"array"

@@ -12,0 +16,0 @@ ],

# d3-array
Utilities for array manipulation: ordering, summarizing, searching, etc.
Data in JavaScript is often represented by an array, and so one tends to manipulate arrays when visualizing or analyzing data. Some common forms of manipulation include taking a contiguous slice (subset) of an array, filtering an array using a predicate function, and mapping an array to a parallel set of values using a transform function. Before looking at the set of utilities that this module provides, familiarize yourself with the powerful [array methods built-in to JavaScript](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/prototype).
When using D3—and with data in general—you tend to do a lot of array manipulation. Some common forms of array manipulation include taking a contiguous slice (subset) of an array, filtering an array using a predicate function, and mapping an array to a parallel set of values using a transform function. Before looking at the set of utilities that D3 provides for arrays, you should familiarize yourself with the powerful [array methods built-in to JavaScript](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/prototype).
JavaScript includes **mutation methods** that modify the array:
* [array.pop](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop) - Remove the last element from the array.
* [array.push](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push) - Add one or more elements to the end of the array.
* [array.reverse](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse) - Reverse the order of the elements of the array.
* [array.shift](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift) - Remove the first element from the array.
* [array.sort](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort) - Sort the elements of the array.
* [array.splice](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice) - Add or remove elements from the array.
* [array.unshift](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift) - Add one or more elements to the front of the array.
* [*array*.pop](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop) - Remove the last element from the array.
* [*array*.push](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push) - Add one or more elements to the end of the array.
* [*array*.reverse](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse) - Reverse the order of the elements of the array.
* [*array*.shift](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift) - Remove the first element from the array.
* [*array*.sort](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort) - Sort the elements of the array.
* [*array*.splice](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice) - Add or remove elements from the array.
* [*array*.unshift](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift) - Add one or more elements to the front of the array.
There are also **access methods** that return some representation of the array:
* [array.concat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat) - Join the array with other array(s) or value(s).
* [array.join](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join) - Join all elements of the array into a string.
* [array.slice](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice) - Extract a section of the array.
* [array.indexOf](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf) - Find the first occurrence of a value within the array.
* [array.lastIndexOf](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf) - Find the last occurrence of a value within the array.
* [*array*.concat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat) - Join the array with other array(s) or value(s).
* [*array*.join](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join) - Join all elements of the array into a string.
* [*array*.slice](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice) - Extract a section of the array.
* [*array*.indexOf](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf) - Find the first occurrence of a value within the array.
* [*array*.lastIndexOf](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf) - Find the last occurrence of a value within the array.
And finally **iteration methods** that apply functions to elements in the array:
* [array.filter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter) - Create a new array with only the elements for which a predicate is true.
* [array.forEach](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach) - Call a function for each element in the array.
* [array.every](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every) - See if every element in the array satisfies a predicate.
* [array.map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) - Create a new array with the result of calling a function on every element in the array.
* [array.some](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some) - See if at least one element in the array satisfies a predicate.
* [array.reduce](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce) - Apply a function to reduce the array to a single value (from left-to-right).
* [array.reduceRight](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduceRight) - Apply a function to reduce the array to a single value (from right-to-left).
* [*array*.filter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter) - Create a new array with only the elements for which a predicate is true.
* [*array*.forEach](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach) - Call a function for each element in the array.
* [*array*.every](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every) - See if every element in the array satisfies a predicate.
* [*array*.map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) - Create a new array with the result of calling a function on every element in the array.
* [*array*.some](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some) - See if at least one element in the array satisfies a predicate.
* [*array*.reduce](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce) - Apply a function to reduce the array to a single value (from left-to-right).
* [*array*.reduceRight](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduceRight) - Apply a function to reduce the array to a single value (from right-to-left).
## Installing
If you use NPM, `npm install d3-array`. Otherwise, download the [latest release](https://github.com/d3/d3-array/releases/latest).
If you use NPM, `npm install d3-array`. Otherwise, download the [latest release](https://github.com/d3/d3-array/releases/latest). The released bundle supports AMD, CommonJS, and vanilla environments. Create a custom build using [Rollup](https://github.com/rollup/rollup) or your preferred bundler. You can also load directly from [d3js.org](https://d3js.org):
## API Reference
<a name="ascending" href="#ascending">#</a> <b>ascending</b>(<i>a</i>, <i>b</i>)
Returns -1 if *a* is less than *b*, or 1 if *a* is greater than *b*, or 0. This is the comparator function for natural order, and can be used in conjunction with the built-in array sort method to arrange elements in ascending order. It is implemented as:
```js
function ascending(a, b) {
return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
}
```html
<script src="https://d3js.org/d3-array.v0.6.min.js"></script>
```
Note that if no comparator function is specified to the built-in sort method, the default order is lexicographic (alphabetical), not natural! This can lead to surprising behavior when sorting an array of numbers.
In a vanilla environment, a `d3_array` global is exported. [Try d3-array in your browser.](https://tonicdev.com/npm/d3-array)
<a name="descending" href="#descending">#</a> <b>descending</b>(<i>a</i>, <i>b</i>)
## API Reference
Returns -1 if *a* is greater than *b*, or 1 if *a* is less than *b*, or 0. This is the comparator function for reverse natural order, and can be used in conjunction with the built-in array sort method to arrange elements in descending order. It is implemented as:
* [Statistics](#statistics)
* [Transformations](#transformations)
* [Search](#search)
* [Objects](#objects)
* [Maps](#maps)
* [Sets](#sets)
* [Nests](#nests)
* [Histograms](#histograms)
* [Histogram Thresholds](#histogram-thresholds)
```js
function descending(a, b) {
return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
}
```
### Statistics
Note that if no comparator function is specified to the built-in sort method, the default order is lexicographic (alphabetical), not natural! This can lead to surprising behavior when sorting an array of numbers.
Methods for computing basic summary statistics.
<a name="min" href="#min">#</a> <b>min</b>(<i>array</i>[, <i>accessor</i>])
<a name="min" href="#min">#</a> d3_array.<b>min</b>(<i>array</i>[, <i>accessor</i>])

@@ -73,3 +67,3 @@ Returns the minimum value in the given *array* using natural order. If the array is empty, returns undefined. An optional *accessor* function may be specified, which is equivalent to calling *array.map(accessor)* before computing the minimum value.

<a name="max" href="#max">#</a> <b>max</b>(<i>array</i>[, <i>accessor</i>])
<a name="max" href="#max">#</a> d3_array.<b>max</b>(<i>array</i>[, <i>accessor</i>])

@@ -82,19 +76,19 @@ Returns the maximum value in the given *array* using natural order. If the array is empty, returns undefined. An optional *accessor* function may be specified, which is equivalent to calling *array.map(accessor)* before computing the maximum value.

<a name="extent" href="#extent">#</a> <b>extent</b>(<i>array</i>[, <i>accessor</i>])
<a name="extent" href="#extent">#</a> d3_array.<b>extent</b>(<i>array</i>[, <i>accessor</i>])
Returns the [minimum](#min) and [maximum](#max) value in the given *array* using natural order.
Returns the [minimum](#min) and [maximum](#max) value in the given *array* using natural order. If the array is empty, returns [undefined, undefined]. An optional *accessor* function may be specified, which is equivalent to calling *array.map(accessor)* before computing the extent.
<a name="sum" href="#sum">#</a> <b>sum</b>(<i>array</i>[, <i>accessor</i>])
<a name="sum" href="#sum">#</a> d3_array.<b>sum</b>(<i>array</i>[, <i>accessor</i>])
Returns the sum of the given *array*. If the array is empty, returns 0. An optional *accessor* function may be specified, which is equivalent to calling *array.map(accessor)* before computing the sum. This method ignores undefined and NaN values; this is useful for ignoring missing data.
<a name="mean" href="#mean">#</a> <b>mean</b>(<i>array</i>[, <i>accessor</i>])
<a name="mean" href="#mean">#</a> d3_array.<b>mean</b>(<i>array</i>[, <i>accessor</i>])
Returns the mean of the given *array*. If the array is empty, returns undefined. An optional *accessor* function may be specified, which is equivalent to calling *array.map(accessor)* before computing the mean. This method ignores undefined and NaN values; this is useful for ignoring missing data.
<a name="median" href="#median">#</a> <b>median</b>(<i>array</i>[, <i>accessor</i>])
<a name="median" href="#median">#</a> d3_array.<b>median</b>(<i>array</i>[, <i>accessor</i>])
Returns the median of the given *array* using the [R-7 method](https://en.wikipedia.org/wiki/Quantile#Estimating_quantiles_from_a_sample). If the array is empty, returns undefined. An optional *accessor* function may be specified, which is equivalent to calling *array.map(accessor)* before computing the median. This method ignores undefined and NaN values; this is useful for ignoring missing data.
<a name="quantile" href="#quantile">#</a> <b>quantile</b>(<i>array</i>, <i>p</i>[, <i>accessor</i>])
<a name="quantile" href="#quantile">#</a> d3_array.<b>quantile</b>(<i>array</i>, <i>p</i>[, <i>accessor</i>])

@@ -105,8 +99,8 @@ Returns the *p*-quantile of the given sorted *array* of elements, where *p* is a number in the range [0,1]. For example, the median can be computed using *p* = 0.5, the first quartile at *p* = 0.25, and the third quartile at *p* = 0.75. This particular implementation uses the [R-7 method](http://en.wikipedia.org/wiki/Quantile#Quantiles_of_a_population), which is the default for the R programming language and Excel. For example:

var a = [0, 10, 30];
quantile(a, 0); // 0
quantile(a, 0.5); // 10
quantile(a, 1); // 30
quantile(a, 0.25); // 5
quantile(a, 0.75); // 20
quantile(a, 0.1); // 2
d3_array.quantile(a, 0); // 0
d3_array.quantile(a, 0.5); // 10
d3_array.quantile(a, 1); // 30
d3_array.quantile(a, 0.25); // 5
d3_array.quantile(a, 0.75); // 20
d3_array.quantile(a, 0.1); // 2
```

@@ -116,15 +110,15 @@

<a name="variance" href="#variance">#</a> <b>variance</b>(<i>array</i>[, <i>accessor</i>])
<a name="variance" href="#variance">#</a> d3_array.<b>variance</b>(<i>array</i>[, <i>accessor</i>])
Returns an [unbiased estimator of the population variance](http://mathworld.wolfram.com/SampleVariance.html) of the given *array* of numbers. If the array has fewer than two values, returns undefined. An optional *accessor* function may be specified, which is equivalent to calling *array.map(accessor)* before computing the variance. This method ignores undefined and NaN values; this is useful for ignoring missing data.
<a name="deviation" href="#deviation">#</a> <b>deviation</b>(<i>array</i>[, <i>accessor</i>])
<a name="deviation" href="#deviation">#</a> d3_array.<b>deviation</b>(<i>array</i>[, <i>accessor</i>])
Returns the standard deviation, defined as the square root of the [bias-corrected variance](#variance), of the given *array* of numbers. If the array has fewer than two values, returns undefined. An optional *accessor* function may be specified, which is equivalent to calling *array.map(accessor)* before computing the standard deviation. This method ignores undefined and NaN values; this is useful for ignoring missing data.
<a name="shuffle" href="#shuffle">#</a> <b>shuffle</b>(<i>array</i>[, <i>lo</i>[, <i>hi</i>]])
### Transformations
Randomizes the order of the specified *array* using the [Fisher–Yates shuffle](http://bost.ocks.org/mike/shuffle/).
Methods for transforming arrays and for generating new arrays.
<a name="merge" href="#merge">#</a> <b>merge</b>(<i>arrays</i>)
<a name="merge" href="#merge">#</a> d3_array.<b>merge</b>(<i>arrays</i>)

@@ -134,74 +128,80 @@ Merges the specified *arrays* into a single array. This method is similar to the built-in array concat method; the only difference is that it is more convenient when you have an array of arrays.

```js
merge([[1], [2, 3]]); // returns [1, 2, 3]
d3_array.merge([[1], [2, 3]]); // returns [1, 2, 3]
```
<a name="range" href="#range">#</a> <b>range</b>([<i>start</i>, ]<i>stop</i>[, <i>step</i>])
<a name="pairs" href="#pairs">#</a> d3_array.<b>pairs</b>(<i>array</i>)
Returns an array containing an arithmetic progression, similar to the Python built-in [range](http://docs.python.org/library/functions.html#range). This method is often used to iterate over a sequence of uniformly-spaced numeric values, such as the indexes of an array or the ticks of a linear scale. (See also [ticks](#ticks) for nicely-rounded values.)
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:
If *step* is omitted, it defaults to 1. If *start* is omitted, it defaults to 0. The *stop* value is exclusive; it is not included in the result. If *step* is positive, the last element is the largest *start* + *i* \* *step* less than *stop*; if *step* is negative, the last element is the smallest *start* + *i* \* *step* greater than *stop*. If the returned array would contain an infinite number of values, an empty range is returned.
The arguments are not required to be integers; however, the results are more predictable if they are. The values in the returned array are defined as *start* + *i* \* *step*, where *i* is an integer from zero to one minus the total number of elements in the returned array. For example:
```js
range(0, 1, 0.2) // [0, 0.2, 0.4, 0.6000000000000001, 0.8]
d3_array.pairs([1, 2, 3, 4]); // returns [[1, 2], [2, 3], [3, 4]]
```
This unexpected behavior is due to IEEE 754 double-precision floating point, which defines 0.2 * 3 = 0.6000000000000001. Use [d3-format](https://github.com/d3/d3-format) to format numbers for human consumption with appropriate rounding; see also [linear.tickFormat](https://github.com/d3/d3-scale#linear_tickFormat) in [d3-scale](https://github.com/d3/d3-scale).
If the specified array has fewer than two elements, returns the empty array.
Likewise, if the returned array should have a specific length, consider using [array.map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) on an integer range. For example:
<a name="permute" href="#permute">#</a> d3_array.<b>permute</b>(<i>array</i>, <i>indexes</i>)
Returns a permutation of the specified *array* using the specified array of *indexes*. The returned array contains the corresponding element in array for each index in indexes, in order. For example, permute(["a", "b", "c"], [1, 2, 0])
returns ["b", "c", "a"]. It is acceptable for the array of indexes to be a different length from the array of elements, and for indexes to be duplicated or omitted.
This method can also be used to extract the values from an object into an array with a stable order. Extracting keyed values in order can be useful for generating data arrays in nested selections. For example:
```js
range(0, 1, 1 / 49); // BAD: returns 50 elements!
range(49).map(function(d) { return d / 49; }); // GOOD: returns 49 elements.
var object = {yield: 27, variety: "Manchuria", year: 1931, site: "University Farm"},
fields = ["site", "variety", "yield"];
d3_array.permute(object, fields); // returns ["University Farm", "Manchuria", 27]
```
<a name="ticks" href="#ticks">#</a> <b>ticks</b>(<i>start</i>, <i>stop</i>, <i>count</i>)
<a name="shuffle" href="#shuffle">#</a> d3_array.<b>shuffle</b>(<i>array</i>[, <i>lo</i>[, <i>hi</i>]])
Randomizes the order of the specified *array* using the [Fisher–Yates shuffle](http://bost.ocks.org/mike/shuffle/).
<a name="ticks" href="#ticks">#</a> d3_array.<b>ticks</b>(<i>start</i>, <i>stop</i>, <i>count</i>)
Returns an array of approximately *count* + 1 uniformly-spaced, nicely-rounded values between *start* and *stop* (inclusive). Each value is a power of ten multiplied by 1, 2 or 5. See also [tickStep](#tickStep) and [*linear*.ticks](https://github.com/d3/d3-scale#linear_ticks). Note that due to the limited precision of IEEE 754 floating point, the returned values may not be exact decimals; use [d3-format](https://github.com/d3/d3-format) to format numbers for human consumption.
<a name="tickStep" href="#tickStep">#</a> <b>tickStep</b>(<i>start</i>, <i>stop</i>, <i>count</i>)
<a name="tickStep" href="#tickStep">#</a> d3_array.<b>tickStep</b>(<i>start</i>, <i>stop</i>, <i>count</i>)
Returns the difference between adjacent tick values if the same arguments were passed to [ticks](#ticks): a nicely-rounded value that is a power of ten multiplied by 1, 2 or 5. Note that due to the limited precision of IEEE 754 floating point, the returned value may not be exact decimals; use [d3-format](https://github.com/d3/d3-format) to format numbers for human consumption.
<a name="permute" href="#permute">#</a> <b>permute</b>(<i>array</i>, <i>indexes</i>)
<a name="range" href="#range">#</a> d3_array.<b>range</b>([<i>start</i>, ]<i>stop</i>[, <i>step</i>])
Returns a permutation of the specified *array* using the specified array of *indexes*. The returned array contains the corresponding element in array for each index in indexes, in order. For example, permute(["a", "b", "c"], [1, 2, 0])
returns ["b", "c", "a"]. It is acceptable for the array of indexes to be a different length from the array of elements, and for indexes to be duplicated or omitted.
Returns an array containing an arithmetic progression, similar to the Python built-in [range](http://docs.python.org/library/functions.html#range). This method is often used to iterate over a sequence of uniformly-spaced numeric values, such as the indexes of an array or the ticks of a linear scale. (See also [ticks](#ticks) for nicely-rounded values.)
This method can also be used to extract the values from an object into an array with a stable order. Extracting keyed values in order can be useful for generating data arrays in nested selections. For example:
If *step* is omitted, it defaults to 1. If *start* is omitted, it defaults to 0. The *stop* value is exclusive; it is not included in the result. If *step* is positive, the last element is the largest *start* + *i* \* *step* less than *stop*; if *step* is negative, the last element is the smallest *start* + *i* \* *step* greater than *stop*. If the returned array would contain an infinite number of values, an empty range is returned.
The arguments are not required to be integers; however, the results are more predictable if they are. The values in the returned array are defined as *start* + *i* \* *step*, where *i* is an integer from zero to one minus the total number of elements in the returned array. For example:
```js
var object = {yield: 27, variety: "Manchuria", year: 1931, site: "University Farm"},
fields = ["site", "variety", "yield"];
permute(object, fields); // returns ["University Farm", "Manchuria", 27]
d3_array.range(0, 1, 0.2) // [0, 0.2, 0.4, 0.6000000000000001, 0.8]
```
<a name="zip" href="#zip">#</a> <b>zip</b>(<i>arrays…</i>)
This unexpected behavior is due to IEEE 754 double-precision floating point, which defines 0.2 * 3 = 0.6000000000000001. Use [d3-format](https://github.com/d3/d3-format) to format numbers for human consumption with appropriate rounding; see also [linear.tickFormat](https://github.com/d3/d3-scale#linear_tickFormat) in [d3-scale](https://github.com/d3/d3-scale).
Returns an array of arrays, where the *i*th array contains the *i*th element from each of the argument *arrays*. The returned array is truncated in length to the shortest array in *arrays*. If *arrays* contains only a single array, the returned array contains one-element arrays. With no arguments, the returned array is empty.
Likewise, if the returned array should have a specific length, consider using [array.map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) on an integer range. For example:
```js
zip([1, 2], [3, 4]); // returns [[1, 3], [2, 4]]
d3_array.range(0, 1, 1 / 49); // BAD: returns 50 elements!
d3_array.range(49).map(function(d) { return d / 49; }); // GOOD: returns 49 elements.
```
<a name="transpose" href="#transpose">#</a> <b>transpose</b>(<i>matrix</i>)
<a name="transpose" href="#transpose">#</a> d3_array.<b>transpose</b>(<i>matrix</i>)
Uses the [zip](#zip) operator as a two-dimensional [matrix transpose](http://en.wikipedia.org/wiki/Transpose).
<a name="pairs" href="#pairs">#</a> <b>pairs</b>(<i>array</i>)
<a name="zip" href="#zip">#</a> d3_array.<b>zip</b>(<i>arrays…</i>)
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:
Returns an array of arrays, where the *i*th array contains the *i*th element from each of the argument *arrays*. The returned array is truncated in length to the shortest array in *arrays*. If *arrays* contains only a single array, the returned array contains one-element arrays. With no arguments, the returned array is empty.
```js
pairs([1, 2, 3, 4]); // returns [[1, 2], [2, 3], [3, 4]]
d3_array.zip([1, 2], [3, 4]); // returns [[1, 3], [2, 4]]
```
If the specified array has fewer than two elements, returns the empty array.
### Search
<a name="scan" href="#scan">#</a> <b>scan</b>(<i>array</i>[, <i>comparator</i>])
Methods for searching arrays for a specific element.
<a name="scan" href="#scan">#</a> d3_array.<b>scan</b>(<i>array</i>[, <i>comparator</i>])
Performs a linear scan of the specified *array*, returning the index of the least element according to the specified *comparator*. If the given *array* contains no comparable elements (*i.e.*, the comparator returns NaN when comparing each element to itself), returns undefined. If *comparator* is not specified, it defaults to [ascending](#ascending). For example:

@@ -211,4 +211,4 @@

var array = [{foo: 42}, {foo: 91}];
scan(array, function(a, b) { return a.foo - b.foo; }); // 0
scan(array, function(a, b) { return b.foo - a.foo; }); // 1
d3_array.scan(array, function(a, b) { return a.foo - b.foo; }); // 0
d3_array.scan(array, function(a, b) { return b.foo - a.foo; }); // 1
```

@@ -218,13 +218,13 @@

<a name="bisectLeft" href="#bisectLeft">#</a> <b>bisectLeft</b>(<i>array</i>, <i>x</i>[, <i>lo</i>[, <i>hi</i>]])
<a name="bisectLeft" href="#bisectLeft">#</a> d3_array.<b>bisectLeft</b>(<i>array</i>, <i>x</i>[, <i>lo</i>[, <i>hi</i>]])
Returns the insertion point for *x* in *array* to maintain sorted order. The arguments *lo* and *hi* may be used to specify a subset of the array which should be considered; by default the entire array is used. If *x* is already present in *array*, the insertion point will be before (to the left of) any existing entries. The return value is suitable for use as the first argument to [splice](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/splice) assuming that *array* is already sorted. The returned insertion point *i* partitions the *array* into two halves so that all *v* < *x* for *v* in *array*.slice(*lo*, *i*) for the left side and all *v* >= *x* for *v* in *array*.slice(*i*, *hi*) for the right side.
<a name="bisect" href="#bisect">#</a> <b>bisect</b>(<i>array</i>, <i>x</i>[, <i>lo</i>[, <i>hi</i>]])<br>
<a name="bisectRight" href="#bisectRight">#</a> <b>bisectRight</b>(<i>array</i>, <i>x</i>[, <i>lo</i>[, <i>hi</i>]])
<a name="bisect" href="#bisect">#</a> d3_array.<b>bisect</b>(<i>array</i>, <i>x</i>[, <i>lo</i>[, <i>hi</i>]])<br>
<a name="bisectRight" href="#bisectRight">#</a> d3_array.<b>bisectRight</b>(<i>array</i>, <i>x</i>[, <i>lo</i>[, <i>hi</i>]])
Similar to [bisectLeft](#bisectLeft), but returns an insertion point which comes after (to the right of) any existing entries of *x* in *array*. The returned insertion point *i* partitions the *array* into two halves so that all *v* <= *x* for *v* in *array*.slice(*lo*, *i*) for the left side and all *v* > *x* for *v* in *array*.slice(*i*, *hi*) for the right side.
<a name="bisector" href="#bisector">#</a> <b>bisector</b>(<i>accessor</i>)
<br><a name="bisector" href="#bisector">#</a> <b>bisector</b>(<i>comparator</i>)
<a name="bisector" href="#bisector">#</a> d3_array.<b>bisector</b>(<i>accessor</i>)
<br><a name="bisector" href="#bisector">#</a> d3_array.<b>bisector</b>(<i>comparator</i>)

@@ -245,3 +245,3 @@ Returns a new bisector using the specified *accessor* or *comparator* function. This method can be used to bisect arrays of objects instead of being limited to simple arrays of primitives. For example, given the following array of objects:

```js
var bisectDate = bisector(function(d) { return d.date; }).right;
var bisectDate = d3_array.bisector(function(d) { return d.date; }).right;
```

@@ -252,3 +252,3 @@

```js
var bisectDate = bisector(function(d, x) { return d.date - x; }).right;
var bisectDate = d3_array.bisector(function(d, x) { return d.date - x; }).right;
```

@@ -266,17 +266,41 @@

### Associative Arrays
<a name="ascending" href="#ascending">#</a> d3_array.<b>ascending</b>(<i>a</i>, <i>b</i>)
Another common data type in JavaScript is the associative array, or more simply the object, which has a set of named properties. Java refers to this as a *map*, and Python a *dictionary*. JavaScript provides a standard mechanism for iterating over the keys (or property names) in an associative array: the [for…in loop](https://developer.mozilla.org/en/JavaScript/Reference/Statements/for...in). However, note that the iteration order is undefined. D3 provides several operators for converting associative arrays to standard arrays with numeric indexes.
Returns -1 if *a* is less than *b*, or 1 if *a* is greater than *b*, or 0. This is the comparator function for natural order, and can be used in conjunction with the built-in [*array*.sort](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort) method to arrange elements in ascending order. It is implemented as:
A word of caution: it is tempting to use plain objects as maps, but this causes [unexpected behavior](http://www.devthought.com/2012/01/18/an-object-is-not-a-hash/) when built-in property names are used as keys, such as `object["__proto__"] = 42` and `"hasOwnProperty" in object`. (ES6 introduces Map and Set collections which avoid this problem, but browser support is limited.) If you cannot guarantee that map keys and set values will be safe, you should use [map](#map) and [set](#set) instead of plain objects.
```js
function ascending(a, b) {
return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
}
```
<a name="keys" href="#keys">#</a> <b>keys</b>(<i>object</i>)
Note that if no comparator function is specified to the built-in sort method, the default order is lexicographic (alphabetical), not natural! This can lead to surprising behavior when sorting an array of numbers.
<a name="descending" href="#descending">#</a> d3_array.<b>descending</b>(<i>a</i>, <i>b</i>)
Returns -1 if *a* is greater than *b*, or 1 if *a* is less than *b*, or 0. This is the comparator function for reverse natural order, and can be used in conjunction with the built-in array sort method to arrange elements in descending order. It is implemented as:
```js
function descending(a, b) {
return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
}
```
Note that if no comparator function is specified to the built-in sort method, the default order is lexicographic (alphabetical), not natural! This can lead to surprising behavior when sorting an array of numbers.
### Objects
A common data type in JavaScript is the *associative array*, or more simply the *object*, which has a set of named properties. The standard mechanism for iterating over the keys (or property names) in an associative array is the [for…in loop](https://developer.mozilla.org/en/JavaScript/Reference/Statements/for...in). However, note that the iteration order is undefined. D3 provides several methods for converting associative arrays to standard arrays with numeric indexes.
A word of caution: it is tempting to use plain objects as maps, but this causes [unexpected behavior](http://www.devthought.com/2012/01/18/an-object-is-not-a-hash/) when built-in property names are used as keys, such as `object["__proto__"] = 42` and `"hasOwnProperty" in object`. If you cannot guarantee that map keys and set values will be safe, use [maps](#maps) and [sets](#sets) (or their ES6 equivalents) instead of plain objects.
<a name="keys" href="#keys">#</a> d3_array.<b>keys</b>(<i>object</i>)
Returns an array containing the property names of the specified object (an associative array). The order of the returned array is undefined.
<a name="values" href="#values">#</a> <b>values</b>(<i>object</i>)
<a name="values" href="#values">#</a> d3_array.<b>values</b>(<i>object</i>)
Returns an array containing the property values of the specified object (an associative array). The order of the returned array is undefined.
<a name="entries" href="#entries">#</a> <b>entries</b>(<i>object</i>)
<a name="entries" href="#entries">#</a> d3_array.<b>entries</b>(<i>object</i>)

@@ -286,3 +310,3 @@ Returns an array containing the property keys and values of the specified object (an associative array). Each entry is an object with a key and value attribute, such as `{key: "foo", value: 42}`. The order of the returned array is undefined.

```js
entries({foo: 42, bar: true}); // [{key: "foo", value: 42}, {key: "bar", value: true}]
d3_array.entries({foo: 42, bar: true}); // [{key: "foo", value: 42}, {key: "bar", value: true}]
```

@@ -300,3 +324,3 @@

<a name="map" href="#map">#</a> <b>map</b>([<i>object</i>[, <i>key</i>]])
<a name="map" href="#map">#</a> d3_array.<b>map</b>([<i>object</i>[, <i>key</i>]])

@@ -306,9 +330,9 @@ Constructs a new map. If *object* is specified, copies all enumerable properties from the specified object into this map. The specified object may also be an array or another map. An optional *key* function may be specified to compute the key for each value in the array. For example:

```js
var m = map([{name: "foo"}, {name: "bar"}], function(d) { return d.name; });
m.get("foo"); // {"name": "foo"}
m.get("bar"); // {"name": "bar"}
m.get("baz"); // undefined
var map = d3_array.map([{name: "foo"}, {name: "bar"}], function(d) { return d.name; });
map.get("foo"); // {"name": "foo"}
map.get("bar"); // {"name": "bar"}
map.get("baz"); // undefined
```
See also [nest](#nest).
See also [nests](#nests).

@@ -328,3 +352,3 @@ <a name="map_has" href="#map_has">#</a> <i>map</i>.<b>has</b>(<i>key</i>)

```js
var m = map()
var map = d3_array.map()
.set("foo", 1)

@@ -334,3 +358,3 @@ .set("bar", 2)

m.get("foo"); // 1
map.get("foo"); // 1
```

@@ -379,3 +403,3 @@

<a name="set" href="#set">#</a> <b>set</b>([<i>array</i>[, <i>accessor</i>]])
<a name="set" href="#set">#</a> d3_array.<b>set</b>([<i>array</i>[, <i>accessor</i>]])

@@ -393,3 +417,3 @@ Constructs a new set. If *array* is specified, adds the given *array* of string values to the returned set. The specified array may also be another set. An optional *accessor* function may be specified, which is equivalent to calling *array.map(accessor)* before constructing the set.

```js
var s = set()
var set = d3_array.set()
.add("foo")

@@ -399,3 +423,3 @@ .add("bar")

s.has("foo"); // true
set.has("foo"); // true
```

@@ -416,3 +440,3 @@

```js
set(["foo", "bar", "foo", "baz"]).values(); // "foo", "bar", "baz"
d3_array.set(["foo", "bar", "foo", "baz"]).values(); // "foo", "bar", "baz"
```

@@ -432,3 +456,3 @@

### Nest
### Nests

@@ -451,3 +475,3 @@ Nesting allows elements in an array to be grouped into a hierarchical tree structure; think of it like the GROUP BY operator in SQL, except you can have multiple levels of grouping, and the resulting output is a tree rather than a flat table. The levels in the tree are specified by key functions. The leaf nodes of the tree can be sorted by value, while the internal nodes can be sorted by key. An optional rollup function will collapse the elements in each leaf node using a summary function. The nest operator (the object returned by [nest](#nest)) is reusable, and does not retain any references to the data that is nested.

```js
var entries = nest()
var entries = d3_array.nest()
.key(function(d) { return d.year; })

@@ -479,3 +503,3 @@ .key(function(d) { return d.variety; })

<a name="nest" href="#nest">#</a> <b>nest</b>()
<a name="nest" href="#nest">#</a> d3_array.<b>nest</b>()

@@ -493,3 +517,3 @@ Creates a new nest operator. The set of keys is initially empty. If the [map](#nest_map) or [entries](#nest_entries) operator is invoked before any key functions are registered, the nest operator simply returns the input array.

```js
var entries = nest()
var entries = d3_array.nest()
.key(function(d) { return d.year; })

@@ -528,3 +552,3 @@ .sortKeys(ascending)

<a name="histogram" href="#histogram">#</a> <b>histogram</b>()
<a name="histogram" href="#histogram">#</a> d3_array.<b>histogram</b>()

@@ -555,3 +579,3 @@ Constructs a new histogram generator with the default settings.

```js
var h = histogram()
var histogram = d3_array.histogram()
.domain(x.domain())

@@ -564,3 +588,3 @@ .thresholds(x.ticks(20));

```js
var bins = h(numbers);
var bins = histogram(numbers);
```

@@ -581,11 +605,11 @@

<a name="thresholdFreedmanDiaconis" href="#thresholdFreedmanDiaconis">#</a> <b>thresholdFreedmanDiaconis</b>(<i>values</i>, <i>min</i>, <i>max</i>)
<a name="thresholdFreedmanDiaconis" href="#thresholdFreedmanDiaconis">#</a> d3_array.<b>thresholdFreedmanDiaconis</b>(<i>values</i>, <i>min</i>, <i>max</i>)
Returns the number of bins according to the [Freedman–Diaconis rule](https://en.wikipedia.org/wiki/Histogram#Mathematical_definition).
<a name="thresholdScott" href="#thresholdScott">#</a> <b>thresholdScott</b>(<i>values</i>, <i>min</i>, <i>max</i>)
<a name="thresholdScott" href="#thresholdScott">#</a> d3_array.<b>thresholdScott</b>(<i>values</i>, <i>min</i>, <i>max</i>)
Returns the number of bins according to [Scott’s normal reference rule](https://en.wikipedia.org/wiki/Histogram#Mathematical_definition).
<a name="thresholdSturges" href="#thresholdSturges">#</a> <b>thresholdSturges</b>(<i>values</i>)
<a name="thresholdSturges" href="#thresholdSturges">#</a> d3_array.<b>thresholdSturges</b>(<i>values</i>)

@@ -598,2 +622,2 @@ Returns the number of bins according to [Sturges’ formula](https://en.wikipedia.org/wiki/Histogram#Mathematical_definition).

* The [range](#range) method now returns the empty array for infinite ranges, rather than throwing an error.
* The [nest.map](#nest_map) method now always returns a [map](#map); use [nest.object](#nest_object) to return a plain object instead.
* The [*nest*.map](#nest_map) method now always returns a [map](#map); use [*nest*.object](#nest_object) to return a plain object instead.
SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc