@stdlib/array-bool
Advanced tools
+1
-1
@@ -1,2 +0,2 @@ | ||
| "use strict";var E=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var q=E(function(X,B){"use strict";var N=require("@stdlib/boolean-ctor");function F(a){var r,e;for(r=[];e=a.next(),!e.done;)r.push(N(e.value));return r}B.exports=F});var V=E(function(Z,A){"use strict";var Y=require("@stdlib/boolean-ctor");function P(a,r,e){var n,t,i;for(n=[],i=-1;t=a.next(),!t.done;)i+=1,n.push(Y(r.call(e,t.value,i)));return n}A.exports=P});var R=E(function($,L){"use strict";var C=require("@stdlib/boolean-ctor");function G(a,r){var e,n;for(e=r.length,n=0;n<e;n++)a[n]=C(r[n]);return a}L.exports=G});var j=E(function(rr,k){"use strict";var p=require("@stdlib/assert-is-nonnegative-integer").isPrimitive,_=require("@stdlib/assert-is-collection"),M=require("@stdlib/assert-is-arraybuffer"),x=require("@stdlib/assert-is-object"),h=require("@stdlib/assert-is-function"),H=require("@stdlib/assert-has-iterator-symbol-support"),d=require("@stdlib/symbol-iterator"),f=require("@stdlib/utils-define-nonenumerable-read-only-property"),T=require("@stdlib/utils-define-nonenumerable-read-only-accessor"),b=require("@stdlib/array-uint8"),y=require("@stdlib/boolean-ctor"),U=require("@stdlib/array-base-getter"),z=require("@stdlib/math-base-special-floor"),D=require("@stdlib/array-base-accessor-getter"),s=require("@stdlib/string-format"),I=q(),J=V(),K=R(),c=b.BYTES_PER_ELEMENT,O=H();function g(a){return typeof a=="object"&&a!==null&&a.constructor.name==="BooleanArray"&&a.BYTES_PER_ELEMENT===c}function S(a){return a===o}function o(){var a,r,e,n,t;if(r=arguments.length,!(this instanceof o))return r===0?new o:r===1?new o(arguments[0]):r===2?new o(arguments[0],arguments[1]):new o(arguments[0],arguments[1],arguments[2]);if(r===0)e=new b(0);else if(r===1)if(t=arguments[0],p(t))e=new b(t);else if(_(t))e=K(new b(t.length),t);else if(M(t))e=new b(t);else if(x(t)){if(O===!1)throw new TypeError(s("invalid argument. Environment lacks Symbol.iterator support. Must provide a length, ArrayBuffer, typed array, or array-like object. Value: `%s`.",t));if(!h(t[d]))throw new TypeError(s("invalid argument. Must provide a length, ArrayBuffer, typed array, array-like object, or an iterable. Value: `%s`.",t));if(e=t[d](),!h(e.next))throw new TypeError(s("invalid argument. Must provide a length, ArrayBuffer, typed array, array-like object, or an iterable. Value: `%s`.",t));e=new b(I(e))}else throw new TypeError(s("invalid argument. Must provide a length, ArrayBuffer, typed array, array-like object, or an iterable. Value: `%s`.",t));else{if(e=arguments[0],!M(e))throw new TypeError(s("invalid argument. First argument must be an ArrayBuffer. Value: `%s`.",e));if(a=arguments[1],!p(a))throw new TypeError(s("invalid argument. Byte offset must be a nonnegative integer. Value: `%s`.",a));if(r===2)e=new b(e,a);else{if(n=arguments[2],!p(n))throw new TypeError(s("invalid argument. Length must be a nonnegative integer. Value: `%s`.",n));if(n*c>e.byteLength-a)throw new RangeError(s("invalid arguments. ArrayBuffer has insufficient capacity. Either decrease the array length or provide a bigger buffer. Minimum capacity: `%u`.",n*c));e=new b(e,a,n)}}return f(this,"_buffer",e),f(this,"_length",e.length),this}f(o,"BYTES_PER_ELEMENT",c);f(o,"name","BooleanArray");f(o,"from",function(r){var e,n,t,i,u,l,m,w,v;if(!h(this))throw new TypeError("invalid invocation. `this` context must be a constructor.");if(!S(this))throw new TypeError("invalid invocation. `this` is not a boolean array.");if(n=arguments.length,n>1){if(t=arguments[1],!h(t))throw new TypeError(s("invalid argument. Second argument must be a function. Value: `%s`.",t));n>2&&(e=arguments[2])}if(_(r)){if(t){for(w=r.length,r.get&&r.set?m=D("default"):m=U("default"),i=new this(w),u=i._buffer,v=0;v<w;v++)u[v]=y(t.call(e,m(r,v),v));return i}return new this(r)}if(x(r)&&O&&h(r[d])){if(u=r[d](),!h(u.next))throw new TypeError(s("invalid argument. First argument must be an array-like object or an iterable. Value: `%s`.",r));for(t?l=J(u,t,e):l=I(u),w=l.length,i=new this(w),u=i._buffer,v=0;v<w;v++)u[v]=l[v];return i}throw new TypeError(s("invalid argument. First argument must be an array-like object or an iterable. Value: `%s`.",r))});f(o,"of",function(){var r,e;if(!h(this))throw new TypeError("invalid invocation. `this` context must be a constructor.");if(!S(this))throw new TypeError("invalid invocation. `this` is not a boolean array.");for(r=[],e=0;e<arguments.length;e++)r.push(arguments[e]);return new this(r)});T(o.prototype,"buffer",function(){return this._buffer.buffer});T(o.prototype,"byteLength",function(){return this._buffer.byteLength});T(o.prototype,"byteOffset",function(){return this._buffer.byteOffset});f(o.prototype,"BYTES_PER_ELEMENT",o.BYTES_PER_ELEMENT);f(o.prototype,"find",function(r,e){var n,t,i;if(!g(this))throw new TypeError("invalid invocation. `this` is not a boolean array.");if(!h(r))throw new TypeError(s("invalid argument. First argument must be a function. Value: `%s`.",r));for(n=this._buffer,i=0;i<this._length;i++)if(t=y(n[i]),r.call(e,t,i,this))return t});f(o.prototype,"findIndex",function(r,e){var n,t,i;if(!g(this))throw new TypeError("invalid invocation. `this` is not a boolean array.");if(!h(r))throw new TypeError(s("invalid argument. First argument must be a function. Value: `%s`.",r));for(n=this._buffer,i=0;i<this._length;i++)if(t=y(n[i]),r.call(e,t,i,this))return i;return-1});f(o.prototype,"findLast",function(r,e){var n,t,i;if(!g(this))throw new TypeError("invalid invocation. `this` is not a boolean array.");if(!h(r))throw new TypeError(s("invalid argument. First argument must be a function. Value: `%s`.",r));for(n=this._buffer,i=this._length-1;i>=0;i--)if(t=y(n[i]),r.call(e,t,i,this))return t});f(o.prototype,"findLastIndex",function(r,e){var n,t,i;if(!g(this))throw new TypeError("invalid invocation. `this` is not a boolean array.");if(!h(r))throw new TypeError(s("invalid argument. First argument must be a function. Value: `%s`.",r));for(n=this._buffer,i=this._length-1;i>=0;i--)if(t=y(n[i]),r.call(e,t,i,this))return i;return-1});f(o.prototype,"get",function(r){if(!g(this))throw new TypeError("invalid invocation. `this` is not a boolean array.");if(!p(r))throw new TypeError(s("invalid argument. Must provide a nonnegative integer. Value: `%s`.",r));if(!(r>=this._length))return y(this._buffer[r])});T(o.prototype,"length",function(){return this._length});f(o.prototype,"map",function(r,e){var n,t,i,u;if(!g(this))throw new TypeError("invalid invocation. `this` is not a boolean array.");if(!h(r))throw new TypeError("invalid argument. First argument must be a function. Value: `%s`.",r);for(i=this._buffer,t=new this.constructor(this._length),n=t._buffer,u=0;u<this._length;u++)n[u]=y(r.call(e,y(i[u]),u,this));return t});f(o.prototype,"reverse",function(){var r,e,n,t,i,u;if(!g(this))throw new TypeError("invalid invocation. `this` is not a boolean array.");for(r=this._buffer,n=this._length,t=z(n/2),i=0;i<t;i++)u=n-i-1,e=r[i],r[i]=r[u],r[u]=e;return this});f(o.prototype,"set",function(r){var e,n,t,i,u,l,m;if(!g(this))throw new TypeError("invalid invocation. `this` is not a boolean array.");if(t=this._buffer,arguments.length>1){if(n=arguments[1],!p(n))throw new TypeError(s("invalid argument. Index argument must be a nonnegative integer. Value: `%s`.",n))}else n=0;if(_(r)){if(u=r.length,n+u>this._length)throw new RangeError("invalid arguments. Target array lacks sufficient storage to accommodate source values.");if(g(r)?e=r._buffer:e=r,m=t.byteOffset+n*c,e.buffer===t.buffer&&e.byteOffset<m&&e.byteOffset+e.byteLength>m){for(i=new b(e.length),l=0;l<e.length;l++)i[l]=e[l];e=i}for(l=0;l<u;n++,l++)t[n]=e[l]?1:0;return}if(n>=this._length)throw new RangeError(s("invalid argument. Index argument is out-of-bounds. Value: `%u`.",n));t[n]=r?1:0});f(o.prototype,"sort",function(r){var e;if(!g(this))throw new TypeError("invalid invocation. `this` is not a boolean array.");if(e=this._buffer,arguments.length===0)return e.sort(),this;if(!h(r))throw new TypeError(s("invalid argument. First argument must be a function. Value: `%s`.",r));return e.sort(n),this;function n(t,i){return r(y(t),y(i))}});f(o.prototype,"toReversed",function(){var r,e,n,t,i;if(!g(this))throw new TypeError("invalid invocation. `this` is not a boolean array.");for(n=this._length,e=new this.constructor(n),t=this._buffer,r=e._buffer,i=0;i<n;i++)r[i]=t[n-i-1];return e});k.exports=o});var Q=j();module.exports=Q; | ||
| "use strict";var d=function(o,r){return function(){return r||o((r={exports:{}}).exports,r),r.exports}};var F=d(function(tr,B){"use strict";var G=require("@stdlib/boolean-ctor");function C(o){var r,t;for(r=[];t=o.next(),!t.done;)r.push(G(t.value));return r}B.exports=C});var A=d(function(er,L){"use strict";var H=require("@stdlib/boolean-ctor");function U(o,r,t){var i,e,n;for(i=[],n=-1;e=o.next(),!e.done;)n+=1,i.push(H(r.call(t,e.value,n)));return i}L.exports=U});var R=d(function(ir,O){"use strict";var z=require("@stdlib/boolean-ctor");function D(o,r){var t,i;for(t=r.length,i=0;i<t;i++)o[i]=z(r[i]);return o}O.exports=D});var W=d(function(nr,Y){"use strict";var T=require("@stdlib/assert-is-nonnegative-integer").isPrimitive,S=require("@stdlib/assert-is-collection"),M=require("@stdlib/assert-is-arraybuffer"),q=require("@stdlib/assert-is-object"),y=require("@stdlib/assert-is-function"),_=require("@stdlib/assert-is-boolean").isPrimitive,b=require("@stdlib/assert-is-integer").isPrimitive,j=require("@stdlib/assert-is-string").isPrimitive,J=require("@stdlib/assert-is-string-array").primitives,K=require("@stdlib/assert-has-iterator-symbol-support"),m=require("@stdlib/symbol-iterator"),s=require("@stdlib/utils-define-nonenumerable-read-only-property"),V=require("@stdlib/utils-define-nonenumerable-read-only-accessor"),c=require("@stdlib/array-uint8"),v=require("@stdlib/boolean-ctor"),Q=require("@stdlib/array-base-getter"),X=require("@stdlib/math-base-special-floor"),Z=require("@stdlib/array-base-accessor-getter"),f=require("@stdlib/string-format"),k=F(),$=A(),I=R(),E=c.BYTES_PER_ELEMENT,N=K();function h(o){return typeof o=="object"&&o!==null&&o.constructor.name==="BooleanArray"&&o.BYTES_PER_ELEMENT===E}function P(o){return o===u}function u(){var o,r,t,i,e;if(r=arguments.length,!(this instanceof u))return r===0?new u:r===1?new u(arguments[0]):r===2?new u(arguments[0],arguments[1]):new u(arguments[0],arguments[1],arguments[2]);if(r===0)t=new c(0);else if(r===1)if(e=arguments[0],T(e))t=new c(e);else if(S(e))t=I(new c(e.length),e);else if(M(e))t=new c(e);else if(q(e)){if(N===!1)throw new TypeError(f("invalid argument. Environment lacks Symbol.iterator support. Must provide a length, ArrayBuffer, typed array, or array-like object. Value: `%s`.",e));if(!y(e[m]))throw new TypeError(f("invalid argument. Must provide a length, ArrayBuffer, typed array, array-like object, or an iterable. Value: `%s`.",e));if(t=e[m](),!y(t.next))throw new TypeError(f("invalid argument. Must provide a length, ArrayBuffer, typed array, array-like object, or an iterable. Value: `%s`.",e));t=new c(k(t))}else throw new TypeError(f("invalid argument. Must provide a length, ArrayBuffer, typed array, array-like object, or an iterable. Value: `%s`.",e));else{if(t=arguments[0],!M(t))throw new TypeError(f("invalid argument. First argument must be an ArrayBuffer. Value: `%s`.",t));if(o=arguments[1],!T(o))throw new TypeError(f("invalid argument. Byte offset must be a nonnegative integer. Value: `%s`.",o));if(r===2)t=new c(t,o);else{if(i=arguments[2],!T(i))throw new TypeError(f("invalid argument. Length must be a nonnegative integer. Value: `%s`.",i));if(i*E>t.byteLength-o)throw new RangeError(f("invalid arguments. ArrayBuffer has insufficient capacity. Either decrease the array length or provide a bigger buffer. Minimum capacity: `%u`.",i*E));t=new c(t,o,i)}}return s(this,"_buffer",t),s(this,"_length",t.length),this}s(u,"BYTES_PER_ELEMENT",E);s(u,"name","BooleanArray");s(u,"from",function(r){var t,i,e,n,a,l,g,p,w;if(!y(this))throw new TypeError("invalid invocation. `this` context must be a constructor.");if(!P(this))throw new TypeError("invalid invocation. `this` is not a boolean array.");if(i=arguments.length,i>1){if(e=arguments[1],!y(e))throw new TypeError(f("invalid argument. Second argument must be a function. Value: `%s`.",e));i>2&&(t=arguments[2])}if(S(r)){if(e){for(p=r.length,r.get&&r.set?g=Z("default"):g=Q("default"),n=new this(p),a=n._buffer,w=0;w<p;w++)a[w]=v(e.call(t,g(r,w),w));return n}return new this(r)}if(q(r)&&N&&y(r[m])){if(a=r[m](),!y(a.next))throw new TypeError(f("invalid argument. First argument must be an array-like object or an iterable. Value: `%s`.",r));for(e?l=$(a,e,t):l=k(a),p=l.length,n=new this(p),a=n._buffer,w=0;w<p;w++)a[w]=l[w];return n}throw new TypeError(f("invalid argument. First argument must be an array-like object or an iterable. Value: `%s`.",r))});s(u,"of",function(){var r,t;if(!y(this))throw new TypeError("invalid invocation. `this` context must be a constructor.");if(!P(this))throw new TypeError("invalid invocation. `this` is not a boolean array.");for(r=[],t=0;t<arguments.length;t++)r.push(arguments[t]);return new this(r)});s(u.prototype,"at",function(r){var t,i;if(!h(this))throw new TypeError("invalid invocation. `this` is not a boolean array.");if(!b(r))throw new TypeError(f("invalid argument. Must provide an integer. Value: `%s`.",r));if(i=this._length,t=this._buffer,r<0&&(r+=i),!(r<0||r>=i))return v(t[r])});V(u.prototype,"buffer",function(){return this._buffer.buffer});V(u.prototype,"byteLength",function(){return this._buffer.byteLength});V(u.prototype,"byteOffset",function(){return this._buffer.byteOffset});s(u.prototype,"BYTES_PER_ELEMENT",u.BYTES_PER_ELEMENT);s(u.prototype,"copyWithin",function(r,t){if(!h(this))throw new TypeError("invalid invocation. `this` is not a boolean array.");return arguments.length===2?this._buffer.copyWithin(r,t):this._buffer.copyWithin(r,t,arguments[2]),this});s(u.prototype,"entries",function(){var r,t,i,e,n,a;if(!h(this))throw new TypeError("invalid invocation. `this` is not a boolean array.");return r=this,e=this._buffer,i=this._length,a=-1,t={},s(t,"next",l),s(t,"return",g),m&&s(t,m,p),t;function l(){return a+=1,n||a>=i?{done:!0}:{value:[a,v(e[a])],done:!1}}function g(w){return n=!0,arguments.length?{value:w,done:!0}:{done:!0}}function p(){return r.entries()}});s(u.prototype,"every",function(r,t){var i,e;if(!h(this))throw new TypeError("invalid invocation. `this` is not a boolean array.");if(!y(r))throw new TypeError(f("invalid argument. First argument must be a function. Value: `%s`.",r));for(i=this._buffer,e=0;e<this._length;e++)if(!r.call(t,v(i[e]),e,this))return!1;return!0});s(u.prototype,"fill",function(r,t,i){var e,n,a,l;if(!h(this))throw new TypeError("invalid invocation. `this` is not a boolean array.");if(!_(r))throw new TypeError(f("invalid argument. First argument must be a boolean. Value: `%s`.",r));if(e=this._buffer,n=this._length,arguments.length>1){if(!b(t))throw new TypeError(f("invalid argument. Second argument must be an integer. Value: `%s`.",t));if(t<0&&(t+=n,t<0&&(t=0)),arguments.length>2){if(!b(i))throw new TypeError(f("invalid argument. Third argument must be an integer. Value: `%s`.",i));i<0&&(i+=n,i<0&&(i=0)),i>n&&(i=n)}else i=n}else t=0,i=n;for(r?a=1:a=0,l=t;l<i;l++)e[l]=a;return this});s(u.prototype,"filter",function(r,t){var i,e,n,a;if(!h(this))throw new TypeError("invalid invocation. `this` is not a boolean array.");if(!y(r))throw new TypeError(f("invalid argument. First argument must be a function. Value: `%s`.",r));for(i=this._buffer,e=[],n=0;n<this._length;n++)a=v(i[n]),r.call(t,a,n,this)&&e.push(a);return new this.constructor(e)});s(u.prototype,"find",function(r,t){var i,e,n;if(!h(this))throw new TypeError("invalid invocation. `this` is not a boolean array.");if(!y(r))throw new TypeError(f("invalid argument. First argument must be a function. Value: `%s`.",r));for(i=this._buffer,n=0;n<this._length;n++)if(e=v(i[n]),r.call(t,e,n,this))return e});s(u.prototype,"findIndex",function(r,t){var i,e,n;if(!h(this))throw new TypeError("invalid invocation. `this` is not a boolean array.");if(!y(r))throw new TypeError(f("invalid argument. First argument must be a function. Value: `%s`.",r));for(i=this._buffer,n=0;n<this._length;n++)if(e=v(i[n]),r.call(t,e,n,this))return n;return-1});s(u.prototype,"findLast",function(r,t){var i,e,n;if(!h(this))throw new TypeError("invalid invocation. `this` is not a boolean array.");if(!y(r))throw new TypeError(f("invalid argument. First argument must be a function. Value: `%s`.",r));for(i=this._buffer,n=this._length-1;n>=0;n--)if(e=v(i[n]),r.call(t,e,n,this))return e});s(u.prototype,"findLastIndex",function(r,t){var i,e,n;if(!h(this))throw new TypeError("invalid invocation. `this` is not a boolean array.");if(!y(r))throw new TypeError(f("invalid argument. First argument must be a function. Value: `%s`.",r));for(i=this._buffer,n=this._length-1;n>=0;n--)if(e=v(i[n]),r.call(t,e,n,this))return n;return-1});s(u.prototype,"forEach",function(r,t){var i,e;if(!h(this))throw new TypeError("invalid invocation. `this` is not a boolean array.");if(!y(r))throw new TypeError(f("invalid argument. First argument must be a function. Value: `%s`.",r));for(i=this._buffer,e=0;e<this._length;e++)r.call(t,v(i[e]),e,this)});s(u.prototype,"get",function(r){if(!h(this))throw new TypeError("invalid invocation. `this` is not a boolean array.");if(!T(r))throw new TypeError(f("invalid argument. Must provide a nonnegative integer. Value: `%s`.",r));if(!(r>=this._length))return v(this._buffer[r])});s(u.prototype,"includes",function(r,t){var i,e;if(!h(this))throw new TypeError("invalid invocation. `this` is not a boolean array.");if(!_(r))throw new TypeError(f("invalid argument. First argument must be a boolean. Value: `%s`.",r));if(arguments.length>1){if(!b(t))throw new TypeError(f("invalid argument. Second argument must be an integer. Value: `%s`.",t));t<0&&(t+=this._length,t<0&&(t=0))}else t=0;for(i=this._buffer,e=t;e<this._length;e++)if(r===v(i[e]))return!0;return!1});s(u.prototype,"indexOf",function(r,t){var i,e;if(!h(this))throw new TypeError("invalid invocation. `this` is not a boolean array.");if(!_(r))throw new TypeError(f("invalid argument. First argument must be a boolean. Value: `%s`.",r));if(arguments.length>1){if(!b(t))throw new TypeError(f("invalid argument. Second argument must be an integer. Value: `%s`.",t));t<0&&(t+=this._length,t<0&&(t=0))}else t=0;for(i=this._buffer,e=t;e<this._length;e++)if(r===v(i[e]))return e;return-1});s(u.prototype,"join",function(r){var t,i,e;if(!h(this))throw new TypeError("invalid invocation. `this` is not a boolean array.");if(arguments.length>0){if(!j(r))throw new TypeError(f("invalid argument. First argument must be a string. Value: `%s`.",r))}else r=",";for(t=this._buffer,i=[],e=0;e<this._length;e++)t[e]?i.push("true"):i.push("false");return i.join(r)});s(u.prototype,"keys",function(){var r,t,i,e,n;if(!h(this))throw new TypeError("invalid invocation. `this` is not a boolean array.");return r=this,i=this._length,n=-1,t={},s(t,"next",a),s(t,"return",l),m&&s(t,m,g),t;function a(){return n+=1,e||n>=i?{done:!0}:{value:n,done:!1}}function l(p){return e=!0,arguments.length?{value:p,done:!0}:{done:!0}}function g(){return r.keys()}});s(u.prototype,"lastIndexOf",function(r,t){var i,e;if(!h(this))throw new TypeError("invalid invocation. `this` is not a boolean array.");if(!_(r))throw new TypeError(f("invalid argument. First argument must be a boolean. Value: `%s`.",r));if(arguments.length>1){if(!b(t))throw new TypeError(f("invalid argument. Second argument must be an integer. Value: `%s`.",t));t>=this._length?t=this._length-1:t<0&&(t+=this._length)}else t=this._length-1;for(i=this._buffer,e=t;e>=0;e--)if(r===v(i[e]))return e;return-1});V(u.prototype,"length",function(){return this._length});s(u.prototype,"map",function(r,t){var i,e,n,a;if(!h(this))throw new TypeError("invalid invocation. `this` is not a boolean array.");if(!y(r))throw new TypeError("invalid argument. First argument must be a function. Value: `%s`.",r);for(n=this._buffer,e=new this.constructor(this._length),i=e._buffer,a=0;a<this._length;a++)i[a]=v(r.call(t,v(n[a]),a,this));return e});s(u.prototype,"reduce",function(r,t){var i,e,n,a;if(!h(this))throw new TypeError("invalid invocation. `this` is not a boolean array.");if(!y(r))throw new TypeError(f("invalid argument. First argument must be a function. Value: `%s`.",r));if(i=this._buffer,e=this._length,arguments.length>1)n=t,a=0;else{if(e===0)throw new Error("invalid operation. If not provided an initial value, an array must contain at least one element.");n=v(i[0]),a=1}for(;a<e;a++)n=r(n,v(i[a]),a,this);return n});s(u.prototype,"reduceRight",function(r,t){var i,e,n,a;if(!h(this))throw new TypeError("invalid invocation. `this` is not a boolean array.");if(!y(r))throw new TypeError(f("invalid argument. First argument must be a function. Value: `%s`.",r));if(i=this._buffer,e=this._length,arguments.length>1)n=t,a=e-1;else{if(e===0)throw new Error("invalid operation. If not provided an initial value, an array must contain at least one element.");n=v(i[e-1]),a=e-2}for(;a>=0;a--)n=r(n,v(i[a]),a,this);return n});s(u.prototype,"reverse",function(){var r,t,i,e,n,a;if(!h(this))throw new TypeError("invalid invocation. `this` is not a boolean array.");for(r=this._buffer,i=this._length,e=X(i/2),n=0;n<e;n++)a=i-n-1,t=r[n],r[n]=r[a],r[a]=t;return this});s(u.prototype,"set",function(r){var t,i,e,n,a,l,g;if(!h(this))throw new TypeError("invalid invocation. `this` is not a boolean array.");if(e=this._buffer,arguments.length>1){if(i=arguments[1],!T(i))throw new TypeError(f("invalid argument. Index argument must be a nonnegative integer. Value: `%s`.",i))}else i=0;if(S(r)){if(a=r.length,i+a>this._length)throw new RangeError("invalid arguments. Target array lacks sufficient storage to accommodate source values.");if(h(r)?t=r._buffer:t=r,g=e.byteOffset+i*E,t.buffer===e.buffer&&t.byteOffset<g&&t.byteOffset+t.byteLength>g){for(n=new c(t.length),l=0;l<t.length;l++)n[l]=t[l];t=n}for(l=0;l<a;i++,l++)e[i]=t[l]?1:0;return}if(i>=this._length)throw new RangeError(f("invalid argument. Index argument is out-of-bounds. Value: `%u`.",i));e[i]=r?1:0});s(u.prototype,"slice",function(r,t){var i,e,n,a,l,g;if(!h(this))throw new TypeError("invalid invocation. `this` is not a boolean array.");if(a=this._buffer,l=this._length,arguments.length===0)r=0,t=l;else{if(!b(r))throw new TypeError(f("invalid argument. First argument must be an integer. Value: `%s`.",r));if(r<0&&(r+=l,r<0&&(r=0)),arguments.length===1)t=l;else{if(!b(t))throw new TypeError(f("invalid argument. Second argument must be an integer. Value: `%s`.",t));t<0?(t+=l,t<0&&(t=0)):t>l&&(t=l)}}for(r<t?i=t-r:i=0,n=new this.constructor(i),e=n._buffer,g=0;g<i;g++)e[g]=a[g+r];return n});s(u.prototype,"some",function(r,t){var i,e;if(!h(this))throw new TypeError("invalid invocation. `this` is not a boolean array.");if(!y(r))throw new TypeError(f("invalid argument. First argument must be a function. Value: `%s`.",r));for(i=this._buffer,e=0;e<this._length;e++)if(r.call(t,v(i[e]),e,this))return!0;return!1});s(u.prototype,"sort",function(r){var t;if(!h(this))throw new TypeError("invalid invocation. `this` is not a boolean array.");if(t=this._buffer,arguments.length===0)return t.sort(),this;if(!y(r))throw new TypeError(f("invalid argument. First argument must be a function. Value: `%s`.",r));return t.sort(i),this;function i(e,n){return r(v(e),v(n))}});s(u.prototype,"subarray",function(r,t){var i,e,n;if(!h(this))throw new TypeError("invalid invocation. `this` is not a boolean array.");if(e=this._buffer,n=this._length,arguments.length===0)r=0,t=n;else{if(!b(r))throw new TypeError(f("invalid argument. First argument must be an integer. Value: `%s`.",r));if(r<0&&(r+=n,r<0&&(r=0)),arguments.length===1)t=n;else{if(!b(t))throw new TypeError(f("invalid argument. Second argument must be an integer. Value: `%s`.",t));t<0?(t+=n,t<0&&(t=0)):t>n&&(t=n)}}return r>=n?(n=0,i=e.byteLength):r>=t?(n=0,i=e.byteOffset+r*E):(n=t-r,i=e.byteOffset+r*E),new this.constructor(e.buffer,i,n<0?0:n)});s(u.prototype,"toLocaleString",function(r,t){var i,e,n,a,l;if(!h(this))throw new TypeError("invalid invocation. `this` is not a boolean array.");if(arguments.length===0)e=[];else if(j(r)||J(r))e=r;else throw new TypeError(f("invalid argument. First argument must be a string or an array of strings. Value: `%s`.",r));if(arguments.length<2)i={};else if(q(t))i=t;else throw new TypeError(f("invalid argument. Options argument must be an object. Value: `%s`.",t));for(a=this._buffer,n=[],l=0;l<this._length;l++)n.push(v(a[l]).toLocaleString(e,i));return n.join(",")});s(u.prototype,"toReversed",function(){var r,t,i,e,n;if(!h(this))throw new TypeError("invalid invocation. `this` is not a boolean array.");for(i=this._length,t=new this.constructor(i),e=this._buffer,r=t._buffer,n=0;n<i;n++)r[n]=e[i-n-1];return t});s(u.prototype,"toSorted",function(r){var t,i,e,n,a;if(!h(this))throw new TypeError("invalid invocation. `this` is not a boolean array.");for(e=this._length,i=new this.constructor(e),n=this._buffer,t=i._buffer,a=0;a<e;a++)t[a]=n[a];if(arguments.length===0)return t.sort(),i;if(!y(r))throw new TypeError(f("invalid argument. First argument must be a function. Value: `%s`.",r));return t.sort(l),i;function l(g,p){return r(v(g),v(p))}});s(u.prototype,"toString",function(){var r,t,i;if(!h(this))throw new TypeError("invalid invocation. `this` is not a boolean array.");for(r=[],t=this._buffer,i=0;i<this._length;i++)t[i]?r.push("true"):r.push("false");return r.join(",")});s(u.prototype,"values",function(){var r,t,i,e,n,a;if(!h(this))throw new TypeError("invalid invocation. `this` is not a boolean array.");return t=this,n=this._buffer,i=this._length,a=-1,r={},s(r,"next",l),s(r,"return",g),m&&s(r,m,p),r;function l(){return a+=1,e||a>=i?{done:!0}:{value:v(n[a]),done:!1}}function g(w){return e=!0,arguments.length?{value:w,done:!0}:{done:!0}}function p(){return t.values()}});s(u.prototype,"with",function(r,t){var i,e,n;if(!h(this))throw new TypeError("invalid invocation. `this` is not a boolean array.");if(!b(r))throw new TypeError(f("invalid argument. First argument must be an integer. Value: `%s`.",r));if(n=this._length,r<0&&(r+=n),r<0||r>=n)throw new RangeError(f("invalid argument. Index argument is out-of-bounds. Value: `%s`.",r));if(!_(t))throw new TypeError(f("invalid argument. Second argument must be a boolean. Value: `%s`.",t));return e=new this.constructor(this._buffer),i=e._buffer,t?i[r]=1:i[r]=0,e});Y.exports=u});var x=W();module.exports=x; | ||
| /** | ||
@@ -3,0 +3,0 @@ * @license Apache-2.0 |
+702
-1
@@ -25,3 +25,3 @@ /* eslint-disable max-lines */ | ||
| import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; | ||
| import { Iterator as Iter, IterableIterator, TypedIterator } from '@stdlib/types/iter'; | ||
| import { ArrayLike, BooleanArray as BooleanArrayInterface } from '@stdlib/types/array'; | ||
@@ -34,2 +34,12 @@ import ArrayBuffer = require( '@stdlib/array-buffer' ); | ||
| /** | ||
| * Locale-specific configuration options. | ||
| */ | ||
| interface LocaleOptions<T = unknown> { | ||
| /** | ||
| * Configuration property. | ||
| */ | ||
| [ key: string | symbol | number ]: T | undefined; | ||
| }; | ||
| /** | ||
| * Callback invoked for each element in a source object. | ||
@@ -114,2 +124,46 @@ * | ||
| * | ||
| * @returns undefined | ||
| */ | ||
| type NullaryCallback<U> = ( this: U ) => void; | ||
| /** | ||
| * Callback invoked for each element in an array. | ||
| * | ||
| * @param value - current array element | ||
| * @returns undefined | ||
| */ | ||
| type UnaryCallback<U> = ( this: U, value: boolean ) => void; | ||
| /** | ||
| * Callback invoked for each element in an array. | ||
| * | ||
| * @param value - current array element | ||
| * @param index - current array element index | ||
| * @returns undefined | ||
| */ | ||
| type BinaryCallback<U> = ( this: U, value: boolean, index: number ) => void; | ||
| /** | ||
| * Callback invoked for each element in an array. | ||
| * | ||
| * @param value - current array element | ||
| * @param index - current array element index | ||
| * @param arr - array on which the method was called | ||
| * @returns undefined | ||
| */ | ||
| type TernaryCallback<U> = ( this: U, value: boolean, index: number, arr: BooleanArray ) => void; | ||
| /** | ||
| * Callback invoked for each element in an array. | ||
| * | ||
| * @param value - current array element | ||
| * @param index - current array element index | ||
| * @param arr - array on which the method was called | ||
| * @returns undefined | ||
| */ | ||
| type Callback<U> = NullaryCallback<U> | UnaryCallback<U> | BinaryCallback<U> | TernaryCallback<U>; | ||
| /** | ||
| * Callback invoked for each element in an array. | ||
| * | ||
| * @returns returned value | ||
@@ -157,2 +211,56 @@ */ | ||
| /** | ||
| * Reducer function invoked for each element in an array. | ||
| * | ||
| * @returns accumulated result | ||
| */ | ||
| type NullaryReducer<U> = () => U; | ||
| /** | ||
| * Reducer function invoked for each element in an array. | ||
| * | ||
| * @param acc - accumulated result | ||
| * @returns accumulated result | ||
| */ | ||
| type UnaryReducer<U> = ( acc: U ) => U; | ||
| /** | ||
| * Reducer function invoked for each element in an array. | ||
| * | ||
| * @param acc - accumulated result | ||
| * @param value - current array element | ||
| * @returns accumulated result | ||
| */ | ||
| type BinaryReducer<U> = ( acc: U, value: boolean ) => U; | ||
| /** | ||
| * Reducer function invoked for each element in an array. | ||
| * | ||
| * @param acc - accumulated result | ||
| * @param value - current array element | ||
| * @param index - current array element index | ||
| * @returns accumulated result | ||
| */ | ||
| type TernaryReducer<U> = ( acc: U, value: boolean, index: number ) => U; | ||
| /** | ||
| * @param acc - accumulated result | ||
| * @param value - current array element | ||
| * @param index - current array element index | ||
| * @param arr - array on which the method was called | ||
| * @returns accumulated result | ||
| */ | ||
| type QuaternaryReducer<U> = ( acc: U, value: boolean, index: number, arr: BooleanArray ) => U; | ||
| /** | ||
| * Reducer function invoked for each element in an array. | ||
| * | ||
| * @param acc - accumulated result | ||
| * @param value - current array element | ||
| * @param index - current array element index | ||
| * @param arr - array on which the method was called | ||
| * @returns accumulated result | ||
| */ | ||
| type Reducer<U> = NullaryReducer<U> | UnaryReducer<U> | BinaryReducer<U> | TernaryReducer<U> | QuaternaryReducer<U>; | ||
| /** | ||
| * Comparator function. | ||
@@ -235,2 +343,27 @@ * | ||
| /** | ||
| * Returns an array element located at integer position (index) `i`, with support for both nonnegative and negative integer indices. | ||
| * | ||
| * @param i - element index | ||
| * @throws index argument must be a integer | ||
| * @returns array element | ||
| * | ||
| * @example | ||
| * var arr = new BooleanArray( 3 ); | ||
| * | ||
| * arr.set( true, 0 ); | ||
| * arr.set( false, 1 ); | ||
| * arr.set( true, 2 ); | ||
| * | ||
| * var v = arr.at( 0 ); | ||
| * // returns true | ||
| * | ||
| * v = arr.at( -1 ); | ||
| * // returns true | ||
| * | ||
| * v = arr.at( 100 ); | ||
| * // returns undefined | ||
| */ | ||
| at( i: number ): boolean | void; | ||
| /** | ||
| * Length (in bytes) of the array. | ||
@@ -280,2 +413,136 @@ * | ||
| /** | ||
| * Copies a sequence of elements within the array to the position starting at `target`. | ||
| * | ||
| * @param target - index at which to start copying elements | ||
| * @param start - source index at which to copy elements from | ||
| * @param end - source index at which to stop copying elements from | ||
| * @returns modified array | ||
| * | ||
| * @example | ||
| * var arr = new BooleanArray( 4 ); | ||
| * | ||
| * arr.set( true, 0 ); | ||
| * arr.set( false, 1 ); | ||
| * arr.set( false, 2 ); | ||
| * arr.set( true, 3 ); | ||
| * | ||
| * // Copy the first two elements to the last two elements: | ||
| * arr.copyWithin( 2, 0, 2 ); | ||
| * | ||
| * var v = arr.get( 2 ); | ||
| * // returns true | ||
| * | ||
| * v = arr.get( 3 ); | ||
| * // returns false | ||
| */ | ||
| copyWithin( target: number, start: number, end?: number ): BooleanArray; | ||
| /** | ||
| * Returns an iterator for iterating over array key-value pairs. | ||
| * | ||
| * @returns iterator | ||
| * | ||
| * @example | ||
| * var arr = new BooleanArray( 3 ); | ||
| * | ||
| * arr.set( true, 0 ); | ||
| * arr.set( false, 1 ); | ||
| * arr.set( true, 2 ); | ||
| * | ||
| * var it = arr.entries(); | ||
| * | ||
| * var v = it.next().value; | ||
| * // returns [ 0, true ] | ||
| * | ||
| * v = it.next().value; | ||
| * // returns [ 1, false ] | ||
| * | ||
| * v = it.next().value; | ||
| * // returns [ 2, true ] | ||
| * | ||
| * var bool = it.next().done; | ||
| * // returns true | ||
| */ | ||
| entries(): TypedIterator<[number, boolean]>; | ||
| /** | ||
| * Tests whether all elements in an array pass a test implemented by a predicate function. | ||
| * | ||
| * @param predicate - predicate function | ||
| * @param thisArg - predicate function execution context | ||
| * @returns boolean indicating whether all elements pass a test | ||
| * | ||
| * @example | ||
| * function predicate( v ) { | ||
| * return v === true; | ||
| * } | ||
| * | ||
| * var arr = new BooleanArray( 3 ); | ||
| * | ||
| * arr.set( true, 0 ); | ||
| * arr.set( true, 1 ); | ||
| * arr.set( true, 2 ); | ||
| * | ||
| * var bool = arr.every( predicate ); | ||
| * // returns true | ||
| */ | ||
| every<U = unknown>( predicate: Predicate<U>, thisArg?: ThisParameterType<Predicate<U>> ): boolean; | ||
| /** | ||
| * Returns a modified typed array filled with a fill value. | ||
| * | ||
| * @param value - fill value | ||
| * @param start - starting index (inclusive) | ||
| * @param end - ending index (exclusive) | ||
| * @returns modified typed array | ||
| * | ||
| * @example | ||
| * var arr = new BooleanArray( 3 ); | ||
| * | ||
| * arr.fill( true, 1 ); | ||
| * | ||
| * var v = arr.get( 0 ); | ||
| * // returns false | ||
| * | ||
| * v = arr.get( 1 ); | ||
| * // returns true | ||
| * | ||
| * v = arr.get( 2 ); | ||
| * // returns true | ||
| */ | ||
| fill( value: boolean, start?: number, end?: number ): BooleanArray; | ||
| /** | ||
| * Returns a new array containing the elements of an array which pass a test implemented by a predicate function. | ||
| * | ||
| * @param predicate - test function | ||
| * @param thisArg - execution context | ||
| * @returns new array containing elements which pass a test implemented by a predicate function | ||
| * | ||
| * @example | ||
| * function predicate( v ) { | ||
| * return ( v === true ); | ||
| * } | ||
| * | ||
| * var arr = new BooleanArray( 3 ); | ||
| * | ||
| * arr.set( true, 0 ); | ||
| * arr.set( false, 1 ); | ||
| * arr.set( true, 2 ); | ||
| * | ||
| * var out = arr.filter( predicate ); | ||
| * // returns <BooleanArray> | ||
| * | ||
| * var len = out.length; | ||
| * // returns 2 | ||
| * | ||
| * var v = out.get( 0 ); | ||
| * // returns true | ||
| * | ||
| * v = out.get( 1 ); | ||
| * // returns true | ||
| */ | ||
| filter<U = unknown>( predicate: Predicate<U>, thisArg?: ThisParameterType<Predicate<U>> ): BooleanArray; | ||
| /** | ||
| * Returns the first element in an array for which a predicate function returns a truthy value. | ||
@@ -373,2 +640,27 @@ * | ||
| /** | ||
| * Invokes a function once for each array element. | ||
| * | ||
| * @param fcn - function to invoke | ||
| * @param thisArg - execution context | ||
| * @returns undefined | ||
| * | ||
| * @example | ||
| * function log( v, i ) { | ||
| * console.log( '%s: %s', i, v.toString() ); | ||
| * } | ||
| * | ||
| * var arr = new BooleanArray( 3 ); | ||
| * | ||
| * arr.set( true, 0 ); | ||
| * arr.set( false, 1 ); | ||
| * arr.set( true, 2 ); | ||
| * | ||
| * arr.forEach( log ); | ||
| * // => 0: true | ||
| * // => 1: false | ||
| * // => 2: true | ||
| */ | ||
| forEach<U = unknown>( fcn: Callback<U>, thisArg?: ThisParameterType<Callback<U>> ): void; | ||
| /** | ||
| * Returns an array element. | ||
@@ -394,2 +686,125 @@ * | ||
| /** | ||
| * Returns a boolean indicating whether an array includes a provided value. | ||
| * | ||
| * @param searchElement - element to search for | ||
| * @param fromIndex - starting index (inclusive) | ||
| * @returns boolean indicating whether an array includes a value | ||
| * | ||
| * @example | ||
| * var arr = new BooleanArray( 5 ); | ||
| * | ||
| * arr.set( true, 0 ); | ||
| * arr.set( false, 1 ); | ||
| * arr.set( true, 2 ); | ||
| * arr.set( true, 3 ); | ||
| * arr.set( true, 4 ); | ||
| * | ||
| * var bool = arr.includes( true ); | ||
| * // returns true | ||
| * | ||
| * bool = arr.includes( false, 2 ); | ||
| * // returns false | ||
| */ | ||
| includes( searchElement: boolean, fromIndex?: number ): boolean; | ||
| /** | ||
| * Returns the first index at which a given element can be found. | ||
| * | ||
| * @param searchElement - element to find | ||
| * @param fromIndex - starting index (inclusive) | ||
| * @returns index or -1 | ||
| * | ||
| * @example | ||
| * var arr = new BooleanArray( 5 ); | ||
| * | ||
| * arr.set( true, 0 ); | ||
| * arr.set( false, 1 ); | ||
| * arr.set( true, 2 ); | ||
| * arr.set( true, 3 ); | ||
| * arr.set( true, 4 ); | ||
| * | ||
| * var idx = arr.indexOf( true ); | ||
| * // returns 0 | ||
| * | ||
| * idx = arr.indexOf( false, 2 ); | ||
| * // returns -1 | ||
| * | ||
| * idx = arr.indexOf( false, -3 ); | ||
| * // returns -1 | ||
| */ | ||
| indexOf( searchElement: boolean, fromIndex?: number ): number; | ||
| /** | ||
| * Returns a new string by concatenating all array elements. | ||
| * | ||
| * @param separator - value separator (default: ',') | ||
| * @returns string | ||
| * | ||
| * @example | ||
| * var arr = new BooleanArray( 3 ); | ||
| * | ||
| * arr.set( true, 0 ); | ||
| * arr.set( false, 1 ); | ||
| * arr.set( true, 2 ); | ||
| * | ||
| * var str = arr.join(); | ||
| * // returns 'true,false,true' | ||
| * | ||
| * str = arr.join( '|' ); | ||
| * // returns 'true|false|true' | ||
| */ | ||
| join( separator?: string ): string; | ||
| /** | ||
| * Returns an iterator for iterating over each index key in a typed array. | ||
| * | ||
| * @returns iterator | ||
| * | ||
| * @example | ||
| * var arr = new BooleanArray( 2 ); | ||
| * | ||
| * arr.set( true, 0 ); | ||
| * arr.set( false, 1 ); | ||
| * | ||
| * var iter = arr.keys(); | ||
| * | ||
| * var v = iter.next().value; | ||
| * // returns 0 | ||
| * | ||
| * v = iter.next().value; | ||
| * // returns 1 | ||
| * | ||
| * var bool = iter.next().done; | ||
| * // returns true | ||
| */ | ||
| keys(): TypedIterator<number>; | ||
| /** | ||
| * Returns the last index at which a given element can be found. | ||
| * | ||
| * @param searchElement - element to find | ||
| * @param fromIndex - index at which to start searching backward (inclusive) | ||
| * @returns index or -1 | ||
| * | ||
| * @example | ||
| * var arr = new BooleanArray( 5 ); | ||
| * | ||
| * arr.set( true, 0 ); | ||
| * arr.set( true, 1 ); | ||
| * arr.set( true, 2 ); | ||
| * arr.set( false, 3 ); | ||
| * arr.set( true, 4 ); | ||
| * | ||
| * var idx = arr.lastIndexOf( true ); | ||
| * // returns 4 | ||
| * | ||
| * idx = arr.lastIndexOf( false, 2 ); | ||
| * // returns -1 | ||
| * | ||
| * idx = arr.lastIndexOf( false, -3 ); | ||
| * // returns -1 | ||
| */ | ||
| lastIndexOf( searchElement: boolean, fromIndex?: number ): number; | ||
| /** | ||
| * Returns a new array with each element being the result of a provided callback function. | ||
@@ -427,2 +842,54 @@ * | ||
| /** | ||
| * Applies a provided callback function to each element of the array, in order, passing in the return value from the calculation on the preceding element and returning the accumulated result upon completion. | ||
| * | ||
| * @param reducer - callback function | ||
| * @param initialValue - initial value | ||
| * @returns accumulated result | ||
| * | ||
| * @example | ||
| * function reducer( acc, v ) { | ||
| * if ( v ) { | ||
| * return acc + 1; | ||
| * } | ||
| * return acc; | ||
| * } | ||
| * | ||
| * var arr = new BooleanArray( 3 ); | ||
| * | ||
| * arr.set( true, 0 ); | ||
| * arr.set( false, 1 ); | ||
| * arr.set( true, 2 ); | ||
| * | ||
| * var out = arr.reduce( reducer, 0 ); | ||
| * // returns 2 | ||
| */ | ||
| reduce<U = unknown>( reducer: Reducer<U>, initialValue?: U ): U; | ||
| /** | ||
| * Applies a provided callback function to each element of the array, in reverse order, passing in the return value from the calculation on the following element and returning the accumulated result upon completion. | ||
| * | ||
| * @param reducer - callback function | ||
| * @param initialValue - initial value | ||
| * @returns accumulated result | ||
| * | ||
| * @example | ||
| * function reducer( acc, v ) { | ||
| * if ( v ) { | ||
| * return acc + 1; | ||
| * } | ||
| * return acc; | ||
| * } | ||
| * | ||
| * var arr = new BooleanArray( 3 ); | ||
| * | ||
| * arr.set( true, 0 ); | ||
| * arr.set( false, 1 ); | ||
| * arr.set( true, 2 ); | ||
| * | ||
| * var out = arr.reduceRight( reducer, 0 ); | ||
| * // returns 2 | ||
| */ | ||
| reduceRight<U = unknown>( reducer: Reducer<U>, initialValue?: U ): U; | ||
| /** | ||
| * Reverses an array in-place. | ||
@@ -497,2 +964,68 @@ * | ||
| /** | ||
| * Copies a portion of a typed array to a new typed array. | ||
| * | ||
| * @param start - starting index (inclusive) | ||
| * @param end - ending index (exclusive) | ||
| * @throws indices must be integers | ||
| * @returns output array | ||
| * | ||
| * @example | ||
| * var arr = new BooleanArray( 5 ); | ||
| * | ||
| * arr.set( true, 0 ); | ||
| * arr.set( false, 1 ); | ||
| * arr.set( true, 2 ); | ||
| * arr.set( false, 3 ); | ||
| * arr.set( true, 4 ); | ||
| * | ||
| * var out = arr.slice(); | ||
| * // returns <BooleanArray> | ||
| * | ||
| * var len = out.length; | ||
| * // returns 5 | ||
| * | ||
| * var bool = out.get( 0 ); | ||
| * // returns true | ||
| * | ||
| * bool = out.get( len-1 ); | ||
| * // returns true | ||
| * | ||
| * out = arr.slice( 1, -2 ); | ||
| * // returns <BooleanArray> | ||
| * | ||
| * len = out.length; | ||
| * // returns 2 | ||
| * | ||
| * bool = out.get( 0 ); | ||
| * // returns false | ||
| * | ||
| * bool = out.get( len-1 ); | ||
| * // returns true | ||
| */ | ||
| slice( start?: number, end?: number ): BooleanArray; | ||
| /** | ||
| * Tests whether at least one element in an array passes a test implemented by a predicate function. | ||
| * | ||
| * @param predicate - predicate function | ||
| * @param thisArg - predicate function execution context | ||
| * @returns boolean indicating whether at least one element passes a test | ||
| * | ||
| * @example | ||
| * function predicate( v ) { | ||
| * return v === true; | ||
| * } | ||
| * | ||
| * var arr = new BooleanArray( 3 ); | ||
| * | ||
| * arr.set( false, 0 ); | ||
| * arr.set( true, 1 ); | ||
| * arr.set( false, 2 ); | ||
| * | ||
| * var bool = arr.some( predicate ); | ||
| * // returns true | ||
| */ | ||
| some<U = unknown>( predicate: Predicate<U>, thisArg?: ThisParameterType<Predicate<U>> ): boolean; | ||
| /** | ||
| * Sorts an array in-place. | ||
@@ -537,2 +1070,64 @@ * | ||
| /** | ||
| * Creates a new typed array view over the same underlying `ArrayBuffer` and with the same underlying data type as the host array. | ||
| * | ||
| * @param begin - starting index (inclusive) | ||
| * @param end - ending index (exclusive) | ||
| * @throws indices must be integers | ||
| * @returns subarray | ||
| * | ||
| * @example | ||
| * var arr = new BooleanArray( 5 ); | ||
| * | ||
| * arr.set( true, 0 ); | ||
| * arr.set( false, 1 ); | ||
| * arr.set( true, 2 ); | ||
| * arr.set( false, 3 ); | ||
| * arr.set( true, 4 ); | ||
| * | ||
| * var subarr = arr.subarray(); | ||
| * // returns <BooleanArray> | ||
| * | ||
| * var len = subarr.length; | ||
| * // returns 5 | ||
| * | ||
| * var bool = subarr.get( 0 ); | ||
| * // returns true | ||
| * | ||
| * bool = subarr.get( len-1 ); | ||
| * // returns true | ||
| * | ||
| * subarr = arr.subarray( 1, -2 ); | ||
| * // returns <BooleanArray> | ||
| * | ||
| * len = subarr.length; | ||
| * // returns 2 | ||
| * | ||
| * bool = subarr.get( 0 ); | ||
| * // returns false | ||
| * | ||
| * bool = subarr.get( len-1 ); | ||
| * // returns true | ||
| */ | ||
| subarray( begin?: number, end?: number ): BooleanArray; | ||
| /** | ||
| * Serializes an array as a locale-specific string. | ||
| * | ||
| * @param locales - locale identifier(s) | ||
| * @param options - configuration options | ||
| * @returns string | ||
| * | ||
| * @example | ||
| * var arr = new BooleanArray( 3 ); | ||
| * | ||
| * arr.set( true, 0 ); | ||
| * arr.set( false, 1 ); | ||
| * arr.set( true, 1 ); | ||
| * | ||
| * var str = arr.toLocaleString(); | ||
| * // returns 'true,false,true' | ||
| */ | ||
| toLocaleString( locales?: string | Array<string>, options?: LocaleOptions ): string; | ||
| /** | ||
| * Returns a new typed array containing the elements in reversed order. | ||
@@ -562,2 +1157,108 @@ * | ||
| toReversed(): BooleanArray; | ||
| /** | ||
| * Returns a new typed array containing the elements in sorted order. | ||
| * | ||
| * @param compareFcn - comparison function | ||
| * @returns sorted array | ||
| * | ||
| * @example | ||
| * function compare( a, b ) { | ||
| * if ( a === false ) { | ||
| * if ( b === false ) { | ||
| * return 0; | ||
| * } | ||
| * return 1; | ||
| * } | ||
| * if ( b === true ) { | ||
| * return 0; | ||
| * } | ||
| * return -1; | ||
| * } | ||
| * | ||
| * var arr = new BooleanArray( 3 ); | ||
| * | ||
| * arr.set( true, 0 ); | ||
| * arr.set( false, 1 ); | ||
| * arr.set( true, 2 ); | ||
| * | ||
| * var out = arr.sort( compare ); | ||
| * // returns <BooleanArray> | ||
| * | ||
| * var v = out.get( 0 ); | ||
| * // returns true | ||
| * | ||
| * v = out.get( 1 ); | ||
| * // returns true | ||
| * | ||
| * v = out.get( 2 ); | ||
| * // returns false | ||
| */ | ||
| toSorted( compareFcn: CompareFcn ): BooleanArray; | ||
| /** | ||
| * Serializes an array as a string. | ||
| * | ||
| * @returns string | ||
| * | ||
| * @example | ||
| * var arr = new BooleanArray( 3 ); | ||
| * | ||
| * arr.set( true, 0 ); | ||
| * arr.set( false, 1 ); | ||
| * arr.set( true, 2 ); | ||
| * | ||
| * var str = arr.toString(); | ||
| * // returns 'true,false,true' | ||
| */ | ||
| toString(): string; | ||
| /** | ||
| * Returns an iterator for iterating over each value in a typed array. | ||
| * | ||
| * @returns iterator | ||
| * | ||
| * @example | ||
| * var arr = new BooleanArray( 2 ); | ||
| * | ||
| * arr.set( true, 0 ); | ||
| * arr.set( false, 1 ); | ||
| * | ||
| * var iter = arr.values(); | ||
| * | ||
| * var v = iter.next().value; | ||
| * // returns true | ||
| * | ||
| * v = iter.next().value; | ||
| * // returns false | ||
| * | ||
| * var bool = iter.next().done; | ||
| * // returns true | ||
| */ | ||
| values(): TypedIterator<boolean>; | ||
| /** | ||
| * Returns a new typed array with the element at a provided index replaced with a provided value. | ||
| * | ||
| * @param index - element index | ||
| * @param value - new value | ||
| * @throws first argument must be an integer | ||
| * @throws second argument must be a boolean | ||
| * @throws index argument is out-of-bounds | ||
| * @returns modified typed array | ||
| * | ||
| * @example | ||
| * var arr = new BooleanArray( 3 ); | ||
| * | ||
| * arr.set( true, 0 ); | ||
| * arr.set( false, 1 ); | ||
| * arr.set( true, 2 ); | ||
| * | ||
| * var out = arr.with( 0, false ); | ||
| * // returns <BooleanArray> | ||
| * | ||
| * var v = out.get( 0 ); | ||
| * // returns false | ||
| */ | ||
| with( index: number, value: boolean ): BooleanArray; | ||
| } | ||
@@ -564,0 +1265,0 @@ |
+1467
-1
@@ -30,2 +30,6 @@ /** | ||
| var isFunction = require( '@stdlib/assert-is-function' ); | ||
| var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; | ||
| var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; | ||
| var isString = require( '@stdlib/assert-is-string' ).isPrimitive; | ||
| var isStringArray = require( '@stdlib/assert-is-string-array' ).primitives; | ||
| var hasIteratorSymbolSupport = require( '@stdlib/assert-has-iterator-symbol-support' ); | ||
@@ -383,2 +387,50 @@ var ITERATOR_SYMBOL = require( '@stdlib/symbol-iterator' ); | ||
| /** | ||
| * Returns an array element located at integer position (index) `i`, with support for both nonnegative and negative integer indices. | ||
| * | ||
| * @name at | ||
| * @memberof BooleanArray.prototype | ||
| * @type {Function} | ||
| * @param {integer} idx - element index | ||
| * @throws {TypeError} `this` must be a boolean array | ||
| * @throws {TypeError} must provide an integer | ||
| * @returns {(boolean|void)} array element | ||
| * | ||
| * @example | ||
| * var arr = new BooleanArray( 3 ); | ||
| * | ||
| * arr.set( true, 0 ); | ||
| * arr.set( false, 1 ); | ||
| * arr.set( true, 2 ); | ||
| * | ||
| * var v = arr.at( 0 ); | ||
| * // returns true | ||
| * | ||
| * v = arr.at( -1 ); | ||
| * // returns true | ||
| * | ||
| * v = arr.at( 100 ); | ||
| * // returns undefined | ||
| */ | ||
| setReadOnly( BooleanArray.prototype, 'at', function at( idx ) { | ||
| var buf; | ||
| var len; | ||
| if ( !isBooleanArray( this ) ) { | ||
| throw new TypeError( 'invalid invocation. `this` is not a boolean array.' ); | ||
| } | ||
| if ( !isInteger( idx ) ) { | ||
| throw new TypeError( format( 'invalid argument. Must provide an integer. Value: `%s`.', idx ) ); | ||
| } | ||
| len = this._length; | ||
| buf = this._buffer; | ||
| if ( idx < 0 ) { | ||
| idx += len; | ||
| } | ||
| if ( idx < 0 || idx >= len ) { | ||
| return; | ||
| } | ||
| return Boolean( buf[ idx ] ); | ||
| }); | ||
| /** | ||
| * Pointer to the underlying data buffer. | ||
@@ -455,2 +507,339 @@ * | ||
| /** | ||
| * Copies a sequence of elements within the array to the position starting at `target`. | ||
| * | ||
| * @name copyWithin | ||
| * @memberof BooleanArray.prototype | ||
| * @type {Function} | ||
| * @param {integer} target - index at which to start copying elements | ||
| * @param {integer} start - source index at which to copy elements from | ||
| * @param {integer} [end] - source index at which to stop copying elements from | ||
| * @throws {TypeError} `this` must be a boolean array | ||
| * @returns {BooleanArray} modified array | ||
| * | ||
| * @example | ||
| * var arr = new BooleanArray( 4 ); | ||
| * | ||
| * arr.set( true, 0 ); | ||
| * arr.set( false, 1 ); | ||
| * arr.set( false, 2 ); | ||
| * arr.set( true, 3 ); | ||
| * | ||
| * // Copy the first two elements to the last two elements: | ||
| * arr.copyWithin( 2, 0, 2 ); | ||
| * | ||
| * var v = arr.get( 2 ); | ||
| * // returns true | ||
| * | ||
| * v = arr.get( 3 ); | ||
| * // returns false | ||
| */ | ||
| setReadOnly( BooleanArray.prototype, 'copyWithin', function copyWithin( target, start ) { | ||
| if ( !isBooleanArray( this ) ) { | ||
| throw new TypeError( 'invalid invocation. `this` is not a boolean array.' ); | ||
| } | ||
| // FIXME: prefer a functional `copyWithin` implementation which addresses lack of universal browser support (e.g., IE11 and Safari) or ensure that typed arrays are polyfilled | ||
| if ( arguments.length === 2 ) { | ||
| this._buffer.copyWithin( target, start ); | ||
| } else { | ||
| this._buffer.copyWithin( target, start, arguments[2] ); | ||
| } | ||
| return this; | ||
| }); | ||
| /** | ||
| * Returns an iterator for iterating over array key-value pairs. | ||
| * | ||
| * @name entries | ||
| * @memberof BooleanArray.prototype | ||
| * @type {Function} | ||
| * @throws {TypeError} `this` must be a boolean array | ||
| * @returns {Iterator} iterator | ||
| * | ||
| * @example | ||
| * var arr = new BooleanArray( 3 ); | ||
| * | ||
| * arr.set( true, 0 ); | ||
| * arr.set( false, 1 ); | ||
| * arr.set( true, 2 ); | ||
| * | ||
| * var it = arr.entries(); | ||
| * | ||
| * var v = it.next().value; | ||
| * // returns [ 0, true ] | ||
| * | ||
| * v = it.next().value; | ||
| * // returns [ 1, false ] | ||
| * | ||
| * v = it.next().value; | ||
| * // returns [ 2, true ] | ||
| * | ||
| * var bool = it.next().done; | ||
| * // returns true | ||
| */ | ||
| setReadOnly( BooleanArray.prototype, 'entries', function entries() { | ||
| var self; | ||
| var iter; | ||
| var len; | ||
| var buf; | ||
| var FLG; | ||
| var i; | ||
| if ( !isBooleanArray( this ) ) { | ||
| throw new TypeError( 'invalid invocation. `this` is not a boolean array.' ); | ||
| } | ||
| self = this; | ||
| buf = this._buffer; | ||
| len = this._length; | ||
| // Initialize an iteration index: | ||
| i = -1; | ||
| // Create an iterator protocol-compliant object: | ||
| iter = {}; | ||
| setReadOnly( iter, 'next', next ); | ||
| setReadOnly( iter, 'return', end ); | ||
| if ( ITERATOR_SYMBOL ) { | ||
| setReadOnly( iter, ITERATOR_SYMBOL, factory ); | ||
| } | ||
| return iter; | ||
| /** | ||
| * Returns an iterator protocol-compliant object containing the next iterated value. | ||
| * | ||
| * @private | ||
| * @returns {Object} iterator protocol-compliant object | ||
| */ | ||
| function next() { | ||
| i += 1; | ||
| if ( FLG || i >= len ) { | ||
| return { | ||
| 'done': true | ||
| }; | ||
| } | ||
| return { | ||
| 'value': [ i, Boolean( buf[ i ] ) ], | ||
| 'done': false | ||
| }; | ||
| } | ||
| /** | ||
| * Finishes an iterator. | ||
| * | ||
| * @private | ||
| * @param {*} [value] - value to return | ||
| * @returns {Object} iterator protocol-compliant object | ||
| */ | ||
| function end( value ) { | ||
| FLG = true; | ||
| if ( arguments.length ) { | ||
| return { | ||
| 'value': value, | ||
| 'done': true | ||
| }; | ||
| } | ||
| return { | ||
| 'done': true | ||
| }; | ||
| } | ||
| /** | ||
| * Returns a new iterator. | ||
| * | ||
| * @private | ||
| * @returns {Iterator} iterator | ||
| */ | ||
| function factory() { | ||
| return self.entries(); | ||
| } | ||
| }); | ||
| /** | ||
| * Tests whether all elements in an array pass a test implemented by a predicate function. | ||
| * | ||
| * @name every | ||
| * @memberof BooleanArray.prototype | ||
| * @type {Function} | ||
| * @param {Function} predicate - predicate function | ||
| * @param {*} [thisArg] - predicate function execution context | ||
| * @throws {TypeError} `this` must be a boolean array | ||
| * @throws {TypeError} first argument must be a function | ||
| * @returns {boolean} boolean indicating whether all elements pass a test | ||
| * | ||
| * @example | ||
| * function predicate( v ) { | ||
| * return v === true; | ||
| * } | ||
| * | ||
| * var arr = new BooleanArray( 3 ); | ||
| * | ||
| * arr.set( true, 0 ); | ||
| * arr.set( true, 1 ); | ||
| * arr.set( true, 2 ); | ||
| * | ||
| * var bool = arr.every( predicate ); | ||
| * // returns true | ||
| */ | ||
| setReadOnly( BooleanArray.prototype, 'every', function every( predicate, thisArg ) { | ||
| var buf; | ||
| var i; | ||
| if ( !isBooleanArray( this ) ) { | ||
| throw new TypeError( 'invalid invocation. `this` is not a boolean array.' ); | ||
| } | ||
| if ( !isFunction( predicate ) ) { | ||
| throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) ); | ||
| } | ||
| buf = this._buffer; | ||
| for ( i = 0; i < this._length; i++ ) { | ||
| if ( !predicate.call( thisArg, Boolean( buf[ i ] ), i, this ) ) { | ||
| return false; | ||
| } | ||
| } | ||
| return true; | ||
| }); | ||
| /** | ||
| * Returns a modified typed array filled with a fill value. | ||
| * | ||
| * @name fill | ||
| * @memberof BooleanArray.prototype | ||
| * @type {Function} | ||
| * @param {boolean} value - fill value | ||
| * @param {integer} [start=0] - starting index (inclusive) | ||
| * @param {integer} [end] - ending index (exclusive) | ||
| * @throws {TypeError} `this` must be a boolean array | ||
| * @throws {TypeError} first argument must be a boolean | ||
| * @throws {TypeError} second argument must be an integer | ||
| * @throws {TypeError} third argument must be an integer | ||
| * @returns {BooleanArray} modified array | ||
| * | ||
| * @example | ||
| * var arr = new BooleanArray( 3 ); | ||
| * | ||
| * arr.fill( true, 1 ); | ||
| * | ||
| * var v = arr.get( 0 ); | ||
| * // returns false | ||
| * | ||
| * v = arr.get( 1 ); | ||
| * // returns true | ||
| * | ||
| * v = arr.get( 2 ); | ||
| * // returns true | ||
| */ | ||
| setReadOnly( BooleanArray.prototype, 'fill', function fill( value, start, end ) { | ||
| var buf; | ||
| var len; | ||
| var val; | ||
| var i; | ||
| if ( !isBooleanArray( this ) ) { | ||
| throw new TypeError( 'invalid invocation. `this` is not a boolean array.' ); | ||
| } | ||
| if ( !isBoolean( value ) ) { | ||
| throw new TypeError( format( 'invalid argument. First argument must be a boolean. Value: `%s`.', value ) ); | ||
| } | ||
| buf = this._buffer; | ||
| len = this._length; | ||
| if ( arguments.length > 1 ) { | ||
| if ( !isInteger( start ) ) { | ||
| throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', start ) ); | ||
| } | ||
| if ( start < 0 ) { | ||
| start += len; | ||
| if ( start < 0 ) { | ||
| start = 0; | ||
| } | ||
| } | ||
| if ( arguments.length > 2 ) { | ||
| if ( !isInteger( end ) ) { | ||
| throw new TypeError( format( 'invalid argument. Third argument must be an integer. Value: `%s`.', end ) ); | ||
| } | ||
| if ( end < 0 ) { | ||
| end += len; | ||
| if ( end < 0 ) { | ||
| end = 0; | ||
| } | ||
| } | ||
| if ( end > len ) { | ||
| end = len; | ||
| } | ||
| } else { | ||
| end = len; | ||
| } | ||
| } else { | ||
| start = 0; | ||
| end = len; | ||
| } | ||
| if ( value ) { | ||
| val = 1; | ||
| } else { | ||
| val = 0; | ||
| } | ||
| for ( i = start; i < end; i++ ) { | ||
| buf[ i ] = val; | ||
| } | ||
| return this; | ||
| }); | ||
| /** | ||
| * Returns a new array containing the elements of an array which pass a test implemented by a predicate function. | ||
| * | ||
| * @name filter | ||
| * @memberof BooleanArray.prototype | ||
| * @type {Function} | ||
| * @param {Function} predicate - test function | ||
| * @param {*} [thisArg] - predicate function execution context | ||
| * @throws {TypeError} `this` must be a boolean array | ||
| * @throws {TypeError} first argument must be a function | ||
| * @returns {BooleanArray} boolean array | ||
| * | ||
| * @example | ||
| * function predicate( v ) { | ||
| * return ( v === true ); | ||
| * } | ||
| * | ||
| * var arr = new BooleanArray( 3 ); | ||
| * | ||
| * arr.set( true, 0 ); | ||
| * arr.set( false, 1 ); | ||
| * arr.set( true, 2 ); | ||
| * | ||
| * var out = arr.filter( predicate ); | ||
| * // returns <BooleanArray> | ||
| * | ||
| * var len = out.length; | ||
| * // returns 2 | ||
| * | ||
| * var v = out.get( 0 ); | ||
| * // returns true | ||
| * | ||
| * v = out.get( 1 ); | ||
| * // returns true | ||
| */ | ||
| setReadOnly( BooleanArray.prototype, 'filter', function filter( predicate, thisArg ) { | ||
| var buf; | ||
| var out; | ||
| var i; | ||
| var v; | ||
| if ( !isBooleanArray( this ) ) { | ||
| throw new TypeError( 'invalid invocation. `this` is not a boolean array.' ); | ||
| } | ||
| if ( !isFunction( predicate ) ) { | ||
| throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) ); | ||
| } | ||
| buf = this._buffer; | ||
| out = []; | ||
| for ( i = 0; i < this._length; i++ ) { | ||
| v = Boolean( buf[ i ] ); | ||
| if ( predicate.call( thisArg, v, i, this ) ) { | ||
| out.push( v ); | ||
| } | ||
| } | ||
| return new this.constructor( out ); | ||
| }); | ||
| /** | ||
| * Returns the first element in an array for which a predicate function returns a truthy value. | ||
@@ -642,2 +1031,42 @@ * | ||
| /** | ||
| * Invokes a function once for each array element. | ||
| * | ||
| * @name forEach | ||
| * @memberof BooleanArray.prototype | ||
| * @type {Function} | ||
| * @param {Function} fcn - function to invoke | ||
| * @param {*} [thisArg] - function invocation context | ||
| * @throws {TypeError} `this` must be a boolean array | ||
| * @throws {TypeError} first argument must be a function | ||
| * | ||
| * @example | ||
| * function log( v, i ) { | ||
| * console.log( '%s: %s', i, v.toString() ); | ||
| * } | ||
| * | ||
| * var arr = new BooleanArray( 3 ); | ||
| * | ||
| * arr.set( true, 0 ); | ||
| * arr.set( false, 1 ); | ||
| * arr.set( true, 2 ); | ||
| * | ||
| * arr.forEach( log ); | ||
| */ | ||
| setReadOnly( BooleanArray.prototype, 'forEach', function forEach( fcn, thisArg ) { | ||
| var buf; | ||
| var i; | ||
| if ( !isBooleanArray( this ) ) { | ||
| throw new TypeError( 'invalid invocation. `this` is not a boolean array.' ); | ||
| } | ||
| if ( !isFunction( fcn ) ) { | ||
| throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', fcn ) ); | ||
| } | ||
| buf = this._buffer; | ||
| for ( i = 0; i < this._length; i++ ) { | ||
| fcn.call( thisArg, Boolean( buf[ i ] ), i, this ); | ||
| } | ||
| }); | ||
| /** | ||
| * Returns an array element. | ||
@@ -681,2 +1110,340 @@ * | ||
| /** | ||
| * Returns a boolean indicating whether an array includes a provided value. | ||
| * | ||
| * @name includes | ||
| * @memberof BooleanArray.prototype | ||
| * @type {Function} | ||
| * @param {boolean} searchElement - search element | ||
| * @param {integer} [fromIndex=0] - starting index (inclusive) | ||
| * @throws {TypeError} `this` must be a boolean array | ||
| * @throws {TypeError} first argument must be a boolean value | ||
| * @throws {TypeError} second argument must be an integer | ||
| * @returns {boolean} boolean indicating whether an array includes a value | ||
| * | ||
| * @example | ||
| * var arr = new BooleanArray( 5 ); | ||
| * | ||
| * arr.set( true, 0 ); | ||
| * arr.set( false, 1 ); | ||
| * arr.set( true, 2 ); | ||
| * arr.set( true, 3 ); | ||
| * arr.set( true, 4 ); | ||
| * | ||
| * var bool = arr.includes( true ); | ||
| * // returns true | ||
| * | ||
| * bool = arr.includes( false, 2 ); | ||
| * // returns false | ||
| */ | ||
| setReadOnly( BooleanArray.prototype, 'includes', function includes( searchElement, fromIndex ) { | ||
| var buf; | ||
| var i; | ||
| if ( !isBooleanArray( this ) ) { | ||
| throw new TypeError( 'invalid invocation. `this` is not a boolean array.' ); | ||
| } | ||
| if ( !isBoolean( searchElement ) ) { | ||
| throw new TypeError( format( 'invalid argument. First argument must be a boolean. Value: `%s`.', searchElement ) ); | ||
| } | ||
| if ( arguments.length > 1 ) { | ||
| if ( !isInteger( fromIndex ) ) { | ||
| throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', fromIndex ) ); | ||
| } | ||
| if ( fromIndex < 0 ) { | ||
| fromIndex += this._length; | ||
| if ( fromIndex < 0 ) { | ||
| fromIndex = 0; | ||
| } | ||
| } | ||
| } else { | ||
| fromIndex = 0; | ||
| } | ||
| buf = this._buffer; | ||
| for ( i = fromIndex; i < this._length; i++ ) { | ||
| if ( searchElement === Boolean( buf[ i ] ) ) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| }); | ||
| /** | ||
| * Returns the first index at which a given element can be found. | ||
| * | ||
| * @name indexOf | ||
| * @memberof BooleanArray.prototype | ||
| * @type {Function} | ||
| * @param {boolean} searchElement - element to find | ||
| * @param {integer} [fromIndex=0] - starting index (inclusive) | ||
| * @throws {TypeError} `this` must be a boolean array | ||
| * @throws {TypeError} first argument must be a boolean value | ||
| * @throws {TypeError} second argument must be an integer | ||
| * @returns {integer} index or -1 | ||
| * | ||
| * @example | ||
| * var arr = new BooleanArray( 5 ); | ||
| * | ||
| * arr.set( true, 0 ); | ||
| * arr.set( false, 1 ); | ||
| * arr.set( true, 2 ); | ||
| * arr.set( true, 3 ); | ||
| * arr.set( true, 4 ); | ||
| * | ||
| * var idx = arr.indexOf( true ); | ||
| * // returns 0 | ||
| * | ||
| * idx = arr.indexOf( false, 2 ); | ||
| * // returns -1 | ||
| * | ||
| * idx = arr.indexOf( false, -3 ); | ||
| * // returns -1 | ||
| */ | ||
| setReadOnly( BooleanArray.prototype, 'indexOf', function indexOf( searchElement, fromIndex ) { | ||
| var buf; | ||
| var i; | ||
| if ( !isBooleanArray( this ) ) { | ||
| throw new TypeError( 'invalid invocation. `this` is not a boolean array.' ); | ||
| } | ||
| if ( !isBoolean( searchElement ) ) { | ||
| throw new TypeError( format( 'invalid argument. First argument must be a boolean. Value: `%s`.', searchElement ) ); | ||
| } | ||
| if ( arguments.length > 1 ) { | ||
| if ( !isInteger( fromIndex ) ) { | ||
| throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', fromIndex ) ); | ||
| } | ||
| if ( fromIndex < 0 ) { | ||
| fromIndex += this._length; | ||
| if ( fromIndex < 0 ) { | ||
| fromIndex = 0; | ||
| } | ||
| } | ||
| } else { | ||
| fromIndex = 0; | ||
| } | ||
| buf = this._buffer; | ||
| for ( i = fromIndex; i < this._length; i++ ) { | ||
| if ( searchElement === Boolean( buf[ i ] ) ) { | ||
| return i; | ||
| } | ||
| } | ||
| return -1; | ||
| }); | ||
| /** | ||
| * Returns a new string by concatenating all array elements. | ||
| * | ||
| * @name join | ||
| * @memberof BooleanArray.prototype | ||
| * @type {Function} | ||
| * @param {string} [separator=','] - element separator | ||
| * @throws {TypeError} `this` must be a boolean array | ||
| * @throws {TypeError} first argument must be a string | ||
| * @returns {string} string representation | ||
| * | ||
| * @example | ||
| * var arr = new BooleanArray( 3 ); | ||
| * | ||
| * arr.set( true, 0 ); | ||
| * arr.set( false, 1 ); | ||
| * arr.set( true, 2 ); | ||
| * | ||
| * var str = arr.join(); | ||
| * // returns 'true,false,true' | ||
| * | ||
| * str = arr.join( '|' ); | ||
| * // returns 'true|false|true' | ||
| */ | ||
| setReadOnly( BooleanArray.prototype, 'join', function join( separator ) { | ||
| var buf; | ||
| var out; | ||
| var i; | ||
| if ( !isBooleanArray( this ) ) { | ||
| throw new TypeError( 'invalid invocation. `this` is not a boolean array.' ); | ||
| } | ||
| if ( arguments.length > 0 ) { | ||
| if ( !isString( separator ) ) { | ||
| throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', separator ) ); | ||
| } | ||
| } else { | ||
| separator = ','; | ||
| } | ||
| buf = this._buffer; | ||
| out = []; | ||
| for ( i = 0; i < this._length; i++ ) { | ||
| if ( buf[i] ) { | ||
| out.push( 'true' ); | ||
| } else { | ||
| out.push( 'false' ); | ||
| } | ||
| } | ||
| return out.join( separator ); | ||
| }); | ||
| /** | ||
| * Returns an iterator for iterating over each index key in a typed array. | ||
| * | ||
| * @name keys | ||
| * @memberof BooleanArray.prototype | ||
| * @type {Function} | ||
| * @throws {TypeError} `this` must be a boolean array | ||
| * @returns {Iterator} iterator | ||
| * | ||
| * @example | ||
| * var arr = new BooleanArray( 2 ); | ||
| * | ||
| * arr.set( true, 0 ); | ||
| * arr.set( false, 1 ); | ||
| * | ||
| * var iter = arr.keys(); | ||
| * | ||
| * var v = iter.next().value; | ||
| * // returns 0 | ||
| * | ||
| * v = iter.next().value; | ||
| * // returns 1 | ||
| * | ||
| * var bool = iter.next().done; | ||
| * // returns true | ||
| */ | ||
| setReadOnly( BooleanArray.prototype, 'keys', function keys() { | ||
| var self; | ||
| var iter; | ||
| var len; | ||
| var FLG; | ||
| var i; | ||
| if ( !isBooleanArray( this ) ) { | ||
| throw new TypeError( 'invalid invocation. `this` is not a boolean array.' ); | ||
| } | ||
| self = this; | ||
| len = this._length; | ||
| // Initialize an iteration index: | ||
| i = -1; | ||
| // Create an iterator protocol-compliant object: | ||
| iter = {}; | ||
| setReadOnly( iter, 'next', next ); | ||
| setReadOnly( iter, 'return', end ); | ||
| if ( ITERATOR_SYMBOL ) { | ||
| setReadOnly( iter, ITERATOR_SYMBOL, factory ); | ||
| } | ||
| return iter; | ||
| /** | ||
| * Returns an iterator protocol-compliant object containing the next iterated value. | ||
| * | ||
| * @private | ||
| * @returns {Object} iterator protocol-compliant object | ||
| */ | ||
| function next() { | ||
| i += 1; | ||
| if ( FLG || i >= len ) { | ||
| return { | ||
| 'done': true | ||
| }; | ||
| } | ||
| return { | ||
| 'value': i, | ||
| 'done': false | ||
| }; | ||
| } | ||
| /** | ||
| * Finishes an iterator. | ||
| * | ||
| * @private | ||
| * @param {*} [value] - value to return | ||
| * @returns {Object} iterator protocol-compliant object | ||
| */ | ||
| function end( value ) { | ||
| FLG = true; | ||
| if ( arguments.length ) { | ||
| return { | ||
| 'value': value, | ||
| 'done': true | ||
| }; | ||
| } | ||
| return { | ||
| 'done': true | ||
| }; | ||
| } | ||
| /** | ||
| * Returns a new iterator. | ||
| * | ||
| * @private | ||
| * @returns {Iterator} iterator | ||
| */ | ||
| function factory() { | ||
| return self.keys(); | ||
| } | ||
| }); | ||
| /** | ||
| * Returns the last index at which a given element can be found. | ||
| * | ||
| * @name lastIndexOf | ||
| * @memberof BooleanArray.prototype | ||
| * @type {Function} | ||
| * @param {boolean} searchElement - element to find | ||
| * @param {integer} [fromIndex] - starting index (inclusive) | ||
| * @throws {TypeError} `this` must be a boolean array | ||
| * @throws {TypeError} first argument must be a boolean value | ||
| * @throws {TypeError} second argument must be an integer | ||
| * @returns {integer} index or -1 | ||
| * | ||
| * @example | ||
| * var arr = new BooleanArray( 5 ); | ||
| * | ||
| * arr.set( true, 0 ); | ||
| * arr.set( true, 1 ); | ||
| * arr.set( true, 2 ); | ||
| * arr.set( false, 3 ); | ||
| * arr.set( true, 4 ); | ||
| * | ||
| * var idx = arr.lastIndexOf( true ); | ||
| * // returns 4 | ||
| * | ||
| * idx = arr.lastIndexOf( false, 2 ); | ||
| * // returns -1 | ||
| * | ||
| * idx = arr.lastIndexOf( false, -3 ); | ||
| * // returns -1 | ||
| */ | ||
| setReadOnly( BooleanArray.prototype, 'lastIndexOf', function lastIndexOf( searchElement, fromIndex ) { | ||
| var buf; | ||
| var i; | ||
| if ( !isBooleanArray( this ) ) { | ||
| throw new TypeError( 'invalid invocation. `this` is not a boolean array.' ); | ||
| } | ||
| if ( !isBoolean( searchElement ) ) { | ||
| throw new TypeError( format( 'invalid argument. First argument must be a boolean. Value: `%s`.', searchElement ) ); | ||
| } | ||
| if ( arguments.length > 1 ) { | ||
| if ( !isInteger( fromIndex ) ) { | ||
| throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', fromIndex ) ); | ||
| } | ||
| if ( fromIndex >= this._length ) { | ||
| fromIndex = this._length - 1; | ||
| } else if ( fromIndex < 0 ) { | ||
| fromIndex += this._length; | ||
| } | ||
| } else { | ||
| fromIndex = this._length - 1; | ||
| } | ||
| buf = this._buffer; | ||
| for ( i = fromIndex; i >= 0; i-- ) { | ||
| if ( searchElement === Boolean( buf[ i ] ) ) { | ||
| return i; | ||
| } | ||
| } | ||
| return -1; | ||
| }); | ||
| /** | ||
| * Number of array elements. | ||
@@ -755,2 +1522,120 @@ * | ||
| /** | ||
| * Applies a provided callback function to each element of the array, in order, passing in the return value from the calculation on the preceding element and returning the accumulated result upon completion. | ||
| * | ||
| * @name reduce | ||
| * @memberof BooleanArray.prototype | ||
| * @type {Function} | ||
| * @param {Function} reducer - callback function | ||
| * @param {*} [initialValue] - initial value | ||
| * @throws {TypeError} `this` must be a boolean array | ||
| * @throws {Error} if not provided an initial value, the array must have at least one element | ||
| * @returns {*} accumulated result | ||
| * | ||
| * @example | ||
| * function reducer( acc, v ) { | ||
| * if ( v ) { | ||
| * return acc + 1; | ||
| * } | ||
| * return acc; | ||
| * } | ||
| * | ||
| * var arr = new BooleanArray( 3 ); | ||
| * | ||
| * arr.set( true, 0 ); | ||
| * arr.set( false, 1 ); | ||
| * arr.set( true, 2 ); | ||
| * | ||
| * var out = arr.reduce( reducer, 0 ); | ||
| * // returns 2 | ||
| */ | ||
| setReadOnly( BooleanArray.prototype, 'reduce', function reduce( reducer, initialValue ) { | ||
| var buf; | ||
| var len; | ||
| var acc; | ||
| var i; | ||
| if ( !isBooleanArray( this ) ) { | ||
| throw new TypeError( 'invalid invocation. `this` is not a boolean array.' ); | ||
| } | ||
| if ( !isFunction( reducer ) ) { | ||
| throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', reducer ) ); | ||
| } | ||
| buf = this._buffer; | ||
| len = this._length; | ||
| if ( arguments.length > 1 ) { | ||
| acc = initialValue; | ||
| i = 0; | ||
| } else { | ||
| if ( len === 0 ) { | ||
| throw new Error( 'invalid operation. If not provided an initial value, an array must contain at least one element.' ); | ||
| } | ||
| acc = Boolean( buf[ 0 ] ); | ||
| i = 1; | ||
| } | ||
| for ( ; i < len; i++ ) { | ||
| acc = reducer( acc, Boolean( buf[ i ] ), i, this ); | ||
| } | ||
| return acc; | ||
| }); | ||
| /** | ||
| * Applies a provided callback function to each element of the array, in reverse order, passing in the return value from the calculation on the preceding element and returning the accumulated result upon completion. | ||
| * | ||
| * @name reduceRight | ||
| * @memberof BooleanArray.prototype | ||
| * @type {Function} | ||
| * @param {Function} reducer - callback function | ||
| * @param {*} [initialValue] - initial value | ||
| * @throws {TypeError} `this` must be a boolean array | ||
| * @throws {Error} if not provided an initial value, the array must have at least one element | ||
| * @returns {*} accumulated result | ||
| * | ||
| * @example | ||
| * function reducer( acc, v ) { | ||
| * if ( v ) { | ||
| * return acc + 1; | ||
| * } | ||
| * return acc; | ||
| * } | ||
| * | ||
| * var arr = new BooleanArray( 3 ); | ||
| * | ||
| * arr.set( true, 0 ); | ||
| * arr.set( false, 1 ); | ||
| * arr.set( true, 2 ); | ||
| * | ||
| * var out = arr.reduceRight( reducer, 0 ); | ||
| * // returns 2 | ||
| */ | ||
| setReadOnly( BooleanArray.prototype, 'reduceRight', function reduceRight( reducer, initialValue ) { | ||
| var buf; | ||
| var len; | ||
| var acc; | ||
| var i; | ||
| if ( !isBooleanArray( this ) ) { | ||
| throw new TypeError( 'invalid invocation. `this` is not a boolean array.' ); | ||
| } | ||
| if ( !isFunction( reducer ) ) { | ||
| throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', reducer ) ); | ||
| } | ||
| buf = this._buffer; | ||
| len = this._length; | ||
| if ( arguments.length > 1 ) { | ||
| acc = initialValue; | ||
| i = len - 1; | ||
| } else { | ||
| if ( len === 0 ) { | ||
| throw new Error( 'invalid operation. If not provided an initial value, an array must contain at least one element.' ); | ||
| } | ||
| acc = Boolean( buf[ len-1 ] ); | ||
| i = len - 2; | ||
| } | ||
| for ( ; i >= 0; i-- ) { | ||
| acc = reducer( acc, Boolean( buf[ i ] ), i, this ); | ||
| } | ||
| return acc; | ||
| }); | ||
| /** | ||
| * Reverses an array in-place. | ||
@@ -909,2 +1794,148 @@ * | ||
| /** | ||
| * Copies a portion of a typed array to a new typed array. | ||
| * | ||
| * @name slice | ||
| * @memberof BooleanArray.prototype | ||
| * @type {Function} | ||
| * @param {integer} [begin] - start index (inclusive) | ||
| * @param {integer} [end] - end index (exclusive) | ||
| * @throws {TypeError} `this` must be a boolean array | ||
| * @throws {TypeError} first argument must be integer | ||
| * @throws {TypeError} second argument must be integer | ||
| * @returns {BooleanArray} boolean array | ||
| * | ||
| * @example | ||
| * var arr = new BooleanArray( 5 ); | ||
| * | ||
| * arr.set( true, 0 ); | ||
| * arr.set( false, 1 ); | ||
| * arr.set( true, 2 ); | ||
| * arr.set( false, 3 ); | ||
| * arr.set( true, 4 ); | ||
| * | ||
| * var out = arr.slice(); | ||
| * // returns <BooleanArray> | ||
| * | ||
| * var len = out.length; | ||
| * // returns 5 | ||
| * | ||
| * var bool = out.get( 0 ); | ||
| * // returns true | ||
| * | ||
| * bool = out.get( len-1 ); | ||
| * // returns true | ||
| * | ||
| * out = arr.slice( 1, -2 ); | ||
| * // returns <BooleanArray> | ||
| * | ||
| * len = out.length; | ||
| * // returns 2 | ||
| * | ||
| * bool = out.get( 0 ); | ||
| * // returns false | ||
| * | ||
| * bool = out.get( len-1 ); | ||
| * // returns true | ||
| */ | ||
| setReadOnly( BooleanArray.prototype, 'slice', function slice( begin, end ) { | ||
| var outlen; | ||
| var outbuf; | ||
| var out; | ||
| var buf; | ||
| var len; | ||
| var i; | ||
| if ( !isBooleanArray( this ) ) { | ||
| throw new TypeError( 'invalid invocation. `this` is not a boolean array.' ); | ||
| } | ||
| buf = this._buffer; | ||
| len = this._length; | ||
| if ( arguments.length === 0 ) { | ||
| begin = 0; | ||
| end = len; | ||
| } else { | ||
| if ( !isInteger( begin ) ) { | ||
| throw new TypeError( format( 'invalid argument. First argument must be an integer. Value: `%s`.', begin ) ); | ||
| } | ||
| if ( begin < 0 ) { | ||
| begin += len; | ||
| if ( begin < 0 ) { | ||
| begin = 0; | ||
| } | ||
| } | ||
| if ( arguments.length === 1 ) { | ||
| end = len; | ||
| } else { | ||
| if ( !isInteger( end ) ) { | ||
| throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', end ) ); | ||
| } | ||
| if ( end < 0 ) { | ||
| end += len; | ||
| if ( end < 0 ) { | ||
| end = 0; | ||
| } | ||
| } else if ( end > len ) { | ||
| end = len; | ||
| } | ||
| } | ||
| } | ||
| if ( begin < end ) { | ||
| outlen = end - begin; | ||
| } else { | ||
| outlen = 0; | ||
| } | ||
| out = new this.constructor( outlen ); | ||
| outbuf = out._buffer; // eslint-disable-line no-underscore-dangle | ||
| for ( i = 0; i < outlen; i++ ) { | ||
| outbuf[ i ] = buf[ i+begin ]; | ||
| } | ||
| return out; | ||
| }); | ||
| /** | ||
| * Tests whether at least one element in an array passes a test implemented by a predicate function. | ||
| * | ||
| * @name some | ||
| * @memberof BooleanArray.prototype | ||
| * @type {Function} | ||
| * @param {Function} predicate - predicate function | ||
| * @param {*} [thisArg] - predicate function execution context | ||
| * @throws {TypeError} `this` must be a boolean array | ||
| * @throws {TypeError} first argument must be a function | ||
| * @returns {boolean} boolean indicating whether at least one element passes a test | ||
| * | ||
| * @example | ||
| * function predicate( v ) { | ||
| * return v === true; | ||
| * } | ||
| * | ||
| * var arr = new BooleanArray( 3 ); | ||
| * | ||
| * arr.set( false, 0 ); | ||
| * arr.set( true, 1 ); | ||
| * arr.set( false, 2 ); | ||
| * | ||
| * var bool = arr.some( predicate ); | ||
| * // returns true | ||
| */ | ||
| setReadOnly( BooleanArray.prototype, 'some', function some( predicate, thisArg ) { | ||
| var buf; | ||
| var i; | ||
| if ( !isBooleanArray( this ) ) { | ||
| throw new TypeError( 'invalid invocation. `this` is not a boolean array.' ); | ||
| } | ||
| if ( !isFunction( predicate ) ) { | ||
| throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) ); | ||
| } | ||
| buf = this._buffer; | ||
| for ( i = 0; i < this._length; i++ ) { | ||
| if ( predicate.call( thisArg, Boolean( buf[ i ] ), i, this ) ) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| }); | ||
| /** | ||
| * Sorts an array in-place. | ||
@@ -950,3 +1981,2 @@ * | ||
| * // returns false | ||
| * | ||
| */ | ||
@@ -984,2 +2014,155 @@ setReadOnly( BooleanArray.prototype, 'sort', function sort( compareFcn ) { | ||
| /** | ||
| * Creates a new typed array view over the same underlying `ArrayBuffer` and with the same underlying data type as the host array. | ||
| * | ||
| * @name subarray | ||
| * @memberof BooleanArray.prototype | ||
| * @type {Function} | ||
| * @param {integer} [begin] - start index (inclusive) | ||
| * @param {integer} [end] - end index (exclusive) | ||
| * @throws {TypeError} `this` must be a boolean array | ||
| * @throws {TypeError} first argument must be an integer | ||
| * @throws {TypeError} second argument must be an integer | ||
| * @returns {BooleanArray} subarray | ||
| * | ||
| * @example | ||
| * var arr = new BooleanArray( 5 ); | ||
| * | ||
| * arr.set( true, 0 ); | ||
| * arr.set( false, 1 ); | ||
| * arr.set( true, 2 ); | ||
| * arr.set( false, 3 ); | ||
| * arr.set( true, 4 ); | ||
| * | ||
| * var subarr = arr.subarray(); | ||
| * // returns <BooleanArray> | ||
| * | ||
| * var len = subarr.length; | ||
| * // returns 5 | ||
| * | ||
| * var bool = subarr.get( 0 ); | ||
| * // returns true | ||
| * | ||
| * bool = subarr.get( len-1 ); | ||
| * // returns true | ||
| * | ||
| * subarr = arr.subarray( 1, -2 ); | ||
| * // returns <BooleanArray> | ||
| * | ||
| * len = subarr.length; | ||
| * // returns 2 | ||
| * | ||
| * bool = subarr.get( 0 ); | ||
| * // returns false | ||
| * | ||
| * bool = subarr.get( len-1 ); | ||
| * // returns true | ||
| */ | ||
| setReadOnly( BooleanArray.prototype, 'subarray', function subarray( begin, end ) { | ||
| var offset; | ||
| var buf; | ||
| var len; | ||
| if ( !isBooleanArray( this ) ) { | ||
| throw new TypeError( 'invalid invocation. `this` is not a boolean array.' ); | ||
| } | ||
| buf = this._buffer; | ||
| len = this._length; | ||
| if ( arguments.length === 0 ) { | ||
| begin = 0; | ||
| end = len; | ||
| } else { | ||
| if ( !isInteger( begin ) ) { | ||
| throw new TypeError( format( 'invalid argument. First argument must be an integer. Value: `%s`.', begin ) ); | ||
| } | ||
| if ( begin < 0 ) { | ||
| begin += len; | ||
| if ( begin < 0 ) { | ||
| begin = 0; | ||
| } | ||
| } | ||
| if ( arguments.length === 1 ) { | ||
| end = len; | ||
| } else { | ||
| if ( !isInteger( end ) ) { | ||
| throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', end ) ); | ||
| } | ||
| if ( end < 0 ) { | ||
| end += len; | ||
| if ( end < 0 ) { | ||
| end = 0; | ||
| } | ||
| } else if ( end > len ) { | ||
| end = len; | ||
| } | ||
| } | ||
| } | ||
| if ( begin >= len ) { | ||
| len = 0; | ||
| offset = buf.byteLength; | ||
| } else if ( begin >= end ) { | ||
| len = 0; | ||
| offset = buf.byteOffset + ( begin*BYTES_PER_ELEMENT ); | ||
| } else { | ||
| len = end - begin; | ||
| offset = buf.byteOffset + ( begin*BYTES_PER_ELEMENT ); | ||
| } | ||
| return new this.constructor( buf.buffer, offset, ( len < 0 ) ? 0 : len ); | ||
| }); | ||
| /** | ||
| * Serializes an array as a locale-specific string. | ||
| * | ||
| * @name toLocaleString | ||
| * @memberof BooleanArray.prototype | ||
| * @type {Function} | ||
| * @param {(string|Array<string>)} [locales] - locale identifier(s) | ||
| * @param {Object} [options] - configuration options | ||
| * @throws {TypeError} `this` must be a boolean array | ||
| * @throws {TypeError} first argument must be a string or an array of strings | ||
| * @throws {TypeError} options argument must be an object | ||
| * @returns {string} string representation | ||
| * | ||
| * @example | ||
| * var arr = new BooleanArray( 3 ); | ||
| * | ||
| * arr.set( true, 0 ); | ||
| * arr.set( false, 1 ); | ||
| * arr.set( true, 2 ); | ||
| * | ||
| * var str = arr.toLocaleString(); | ||
| * // returns 'true,false,true' | ||
| */ | ||
| setReadOnly( BooleanArray.prototype, 'toLocaleString', function toLocaleString( locales, options ) { | ||
| var opts; | ||
| var loc; | ||
| var out; | ||
| var buf; | ||
| var i; | ||
| if ( !isBooleanArray( this ) ) { | ||
| throw new TypeError( 'invalid invocation. `this` is not a boolean array.' ); | ||
| } | ||
| if ( arguments.length === 0 ) { | ||
| loc = []; | ||
| } else if ( isString( locales ) || isStringArray( locales ) ) { | ||
| loc = locales; | ||
| } else { | ||
| throw new TypeError( format( 'invalid argument. First argument must be a string or an array of strings. Value: `%s`.', locales ) ); | ||
| } | ||
| if ( arguments.length < 2 ) { | ||
| opts = {}; | ||
| } else if ( isObject( options ) ) { | ||
| opts = options; | ||
| } else { | ||
| throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); | ||
| } | ||
| buf = this._buffer; | ||
| out = []; | ||
| for ( i = 0; i < this._length; i++ ) { | ||
| out.push( Boolean( buf[ i ] ).toLocaleString( loc, opts ) ); | ||
| } | ||
| return out.join( ',' ); | ||
| }); | ||
| /** | ||
| * Returns a new typed array containing the elements in reversed order. | ||
@@ -1032,5 +2215,288 @@ * | ||
| /** | ||
| * Returns a new typed array containing the elements in sorted order. | ||
| * | ||
| * @name toSorted | ||
| * @memberof BooleanArray.prototype | ||
| * @type {Function} | ||
| * @param {Function} [compareFcn] - comparison function | ||
| * @throws {TypeError} `this` must be a boolean array | ||
| * @throws {TypeError} first argument must be a function | ||
| * @returns {BooleanArray} sorted array | ||
| * | ||
| * @example | ||
| * function compare( a, b ) { | ||
| * if ( a === false ) { | ||
| * if ( b === false ) { | ||
| * return 0; | ||
| * } | ||
| * return 1; | ||
| * } | ||
| * if ( b === true ) { | ||
| * return 0; | ||
| * } | ||
| * return -1; | ||
| * } | ||
| * | ||
| * var arr = new BooleanArray( 3 ); | ||
| * | ||
| * arr.set( true, 0 ); | ||
| * arr.set( false, 1 ); | ||
| * arr.set( true, 2 ); | ||
| * | ||
| * var out = arr.sort( compare ); | ||
| * // returns <BooleanArray> | ||
| * | ||
| * var v = out.get( 0 ); | ||
| * // returns true | ||
| * | ||
| * v = out.get( 1 ); | ||
| * // returns true | ||
| * | ||
| * v = out.get( 2 ); | ||
| * // returns false | ||
| */ | ||
| setReadOnly( BooleanArray.prototype, 'toSorted', function toSorted( compareFcn ) { | ||
| var outbuf; | ||
| var out; | ||
| var len; | ||
| var buf; | ||
| var i; | ||
| if ( !isBooleanArray( this ) ) { | ||
| throw new TypeError( 'invalid invocation. `this` is not a boolean array.' ); | ||
| } | ||
| len = this._length; | ||
| out = new this.constructor( len ); | ||
| buf = this._buffer; | ||
| outbuf = out._buffer; // eslint-disable-line no-underscore-dangle | ||
| for ( i = 0; i < len; i++ ) { | ||
| outbuf[ i ] = buf[ i ]; | ||
| } | ||
| if ( arguments.length === 0 ) { | ||
| outbuf.sort(); | ||
| return out; | ||
| } | ||
| if ( !isFunction( compareFcn ) ) { | ||
| throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', compareFcn ) ); | ||
| } | ||
| outbuf.sort( compare ); | ||
| return out; | ||
| /** | ||
| * Comparison function for sorting. | ||
| * | ||
| * @private | ||
| * @param {boolean} a - first boolean value for comparison | ||
| * @param {boolean} b - second boolean value for comparison | ||
| * @returns {number} comparison result | ||
| */ | ||
| function compare( a, b ) { | ||
| return compareFcn( Boolean( a ), Boolean( b ) ); | ||
| } | ||
| }); | ||
| /** | ||
| * Serializes an array as a string. | ||
| * | ||
| * @name toString | ||
| * @memberof BooleanArray.prototype | ||
| * @type {Function} | ||
| * @throws {TypeError} `this` must be a boolean array | ||
| * @returns {string} string representation | ||
| * | ||
| * @example | ||
| * var arr = new BooleanArray( 3 ); | ||
| * | ||
| * arr.set( true, 0 ); | ||
| * arr.set( false, 1 ); | ||
| * arr.set( true, 2 ); | ||
| * | ||
| * var str = arr.toString(); | ||
| * // returns 'true,false,true' | ||
| */ | ||
| setReadOnly( BooleanArray.prototype, 'toString', function toString() { | ||
| var out; | ||
| var buf; | ||
| var i; | ||
| if ( !isBooleanArray( this ) ) { | ||
| throw new TypeError( 'invalid invocation. `this` is not a boolean array.' ); | ||
| } | ||
| out = []; | ||
| buf = this._buffer; | ||
| for ( i = 0; i < this._length; i++ ) { | ||
| if ( buf[i] ) { | ||
| out.push( 'true' ); | ||
| } else { | ||
| out.push( 'false' ); | ||
| } | ||
| } | ||
| return out.join( ',' ); | ||
| }); | ||
| /** | ||
| * Returns an iterator for iterating over each value in a typed array. | ||
| * | ||
| * @name values | ||
| * @memberof BooleanArray.prototype | ||
| * @type {Function} | ||
| * @throws {TypeError} `this` must be a boolean array | ||
| * @returns {Iterator} iterator | ||
| * | ||
| * @example | ||
| * var arr = new BooleanArray( 2 ); | ||
| * | ||
| * arr.set( true, 0 ); | ||
| * arr.set( false, 1 ); | ||
| * | ||
| * var iter = arr.values(); | ||
| * | ||
| * var v = iter.next().value; | ||
| * // returns true | ||
| * | ||
| * v = iter.next().value; | ||
| * // returns false | ||
| * | ||
| * var bool = iter.next().done; | ||
| * // returns true | ||
| */ | ||
| setReadOnly( BooleanArray.prototype, 'values', function values() { | ||
| var iter; | ||
| var self; | ||
| var len; | ||
| var FLG; | ||
| var buf; | ||
| var i; | ||
| if ( !isBooleanArray( this ) ) { | ||
| throw new TypeError( 'invalid invocation. `this` is not a boolean array.' ); | ||
| } | ||
| self = this; | ||
| buf = this._buffer; | ||
| len = this._length; | ||
| // Initialize an iteration index: | ||
| i = -1; | ||
| // Create an iterator protocol-compliant object: | ||
| iter = {}; | ||
| setReadOnly( iter, 'next', next ); | ||
| setReadOnly( iter, 'return', end ); | ||
| if ( ITERATOR_SYMBOL ) { | ||
| setReadOnly( iter, ITERATOR_SYMBOL, factory ); | ||
| } | ||
| return iter; | ||
| /** | ||
| * Returns an iterator protocol-compliant object containing the next iterated value. | ||
| * | ||
| * @private | ||
| * @returns {Object} iterator protocol-compliant object | ||
| */ | ||
| function next() { | ||
| i += 1; | ||
| if ( FLG || i >= len ) { | ||
| return { | ||
| 'done': true | ||
| }; | ||
| } | ||
| return { | ||
| 'value': Boolean( buf[ i ] ), | ||
| 'done': false | ||
| }; | ||
| } | ||
| /** | ||
| * Finishes an iterator. | ||
| * | ||
| * @private | ||
| * @param {*} [value] - value to return | ||
| * @returns {Object} iterator protocol-compliant object | ||
| */ | ||
| function end( value ) { | ||
| FLG = true; | ||
| if ( arguments.length ) { | ||
| return { | ||
| 'value': value, | ||
| 'done': true | ||
| }; | ||
| } | ||
| return { | ||
| 'done': true | ||
| }; | ||
| } | ||
| /** | ||
| * Returns a new iterator. | ||
| * | ||
| * @private | ||
| * @returns {Iterator} iterator | ||
| */ | ||
| function factory() { | ||
| return self.values(); | ||
| } | ||
| }); | ||
| /** | ||
| * Returns a new typed array with the element at a provided index replaced with a provided value. | ||
| * | ||
| * @name with | ||
| * @memberof BooleanArray.prototype | ||
| * @type {Function} | ||
| * @param {integer} index - element index | ||
| * @param {boolean} value - new value | ||
| * @throws {TypeError} `this` must be a boolean array | ||
| * @throws {TypeError} first argument must be an integer | ||
| * @throws {RangeError} index argument is out-of-bounds | ||
| * @throws {TypeError} second argument must be a boolean | ||
| * @returns {BooleanArray} new typed array | ||
| * | ||
| * @example | ||
| * var arr = new BooleanArray( 3 ); | ||
| * | ||
| * arr.set( true, 0 ); | ||
| * arr.set( false, 1 ); | ||
| * arr.set( true, 2 ); | ||
| * | ||
| * var out = arr.with( 0, false ); | ||
| * // returns <BooleanArray> | ||
| * | ||
| * var v = out.get( 0 ); | ||
| * // returns false | ||
| */ | ||
| setReadOnly( BooleanArray.prototype, 'with', function copyWith( index, value ) { | ||
| var buf; | ||
| var out; | ||
| var len; | ||
| if ( !isBooleanArray( this ) ) { | ||
| throw new TypeError( 'invalid invocation. `this` is not a boolean array.' ); | ||
| } | ||
| if ( !isInteger( index ) ) { | ||
| throw new TypeError( format( 'invalid argument. First argument must be an integer. Value: `%s`.', index ) ); | ||
| } | ||
| len = this._length; | ||
| if ( index < 0 ) { | ||
| index += len; | ||
| } | ||
| if ( index < 0 || index >= len ) { | ||
| throw new RangeError( format( 'invalid argument. Index argument is out-of-bounds. Value: `%s`.', index ) ); | ||
| } | ||
| if ( !isBoolean( value ) ) { | ||
| throw new TypeError( format( 'invalid argument. Second argument must be a boolean. Value: `%s`.', value ) ); | ||
| } | ||
| out = new this.constructor( this._buffer ); | ||
| buf = out._buffer; // eslint-disable-line no-underscore-dangle | ||
| if ( value ) { | ||
| buf[ index ] = 1; | ||
| } else { | ||
| buf[ index ] = 0; | ||
| } | ||
| return out; | ||
| }); | ||
| // EXPORTS // | ||
| module.exports = BooleanArray; |
+20
-16
| { | ||
| "name": "@stdlib/array-bool", | ||
| "version": "0.0.1", | ||
| "version": "0.1.0", | ||
| "description": "BooleanArray.", | ||
@@ -34,17 +34,21 @@ "license": "Apache-2.0", | ||
| "@stdlib/array-base-accessor-getter": "^0.2.1", | ||
| "@stdlib/array-base-getter": "^0.2.1", | ||
| "@stdlib/array-uint8": "^0.2.1", | ||
| "@stdlib/assert-has-iterator-symbol-support": "^0.2.1", | ||
| "@stdlib/assert-is-arraybuffer": "^0.2.1", | ||
| "@stdlib/assert-is-collection": "^0.2.1", | ||
| "@stdlib/assert-is-function": "^0.2.1", | ||
| "@stdlib/assert-is-nonnegative-integer": "^0.2.1", | ||
| "@stdlib/assert-is-object": "^0.2.1", | ||
| "@stdlib/boolean-ctor": "^0.2.1", | ||
| "@stdlib/math-base-special-floor": "^0.2.2", | ||
| "@stdlib/string-format": "^0.2.1", | ||
| "@stdlib/symbol-iterator": "^0.2.1", | ||
| "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.2", | ||
| "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", | ||
| "@stdlib/error-tools-fmtprodmsg": "^0.2.1" | ||
| "@stdlib/array-base-getter": "^0.2.2", | ||
| "@stdlib/array-uint8": "^0.2.2", | ||
| "@stdlib/assert-has-iterator-symbol-support": "^0.2.2", | ||
| "@stdlib/assert-is-arraybuffer": "^0.2.2", | ||
| "@stdlib/assert-is-boolean": "^0.2.2", | ||
| "@stdlib/assert-is-collection": "^0.2.2", | ||
| "@stdlib/assert-is-function": "^0.2.2", | ||
| "@stdlib/assert-is-integer": "^0.2.2", | ||
| "@stdlib/assert-is-nonnegative-integer": "^0.2.2", | ||
| "@stdlib/assert-is-object": "^0.2.2", | ||
| "@stdlib/assert-is-string": "^0.2.2", | ||
| "@stdlib/assert-is-string-array": "^0.2.2", | ||
| "@stdlib/boolean-ctor": "^0.2.2", | ||
| "@stdlib/math-base-special-floor": "^0.2.3", | ||
| "@stdlib/string-format": "^0.2.2", | ||
| "@stdlib/symbol-iterator": "^0.2.2", | ||
| "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.3", | ||
| "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", | ||
| "@stdlib/error-tools-fmtprodmsg": "^0.2.2" | ||
| }, | ||
@@ -51,0 +55,0 @@ "devDependencies": {}, |
+979
-3
@@ -360,2 +360,321 @@ <!-- | ||
| <a name="method-at"></a> | ||
| #### BooleanArray.prototype.at( i ) | ||
| Returns an array element located at integer position (index) `i`, with support for both nonnegative and negative integer positions. | ||
| ```javascript | ||
| var arr = new BooleanArray( 3 ); | ||
| arr.set( true, 0 ); | ||
| arr.set( false, 1 ); | ||
| arr.set( true, 2 ); | ||
| var v = arr.at( 0 ); | ||
| // returns true | ||
| v = arr.at( -1 ); | ||
| // returns true | ||
| ``` | ||
| If provided an out-of-bounds index, the method returns `undefined`. | ||
| ```javascript | ||
| var arr = new BooleanArray( 10 ); | ||
| var v = arr.at( 100 ); | ||
| // returns undefined | ||
| v = arr.at( -100 ); | ||
| // returns undefined | ||
| ``` | ||
| <a name="method-copy-within"></a> | ||
| #### BooleanArray.prototype.copyWithin( target, start\[, end] ) | ||
| Copies a sequence of elements within the array starting at `start` and ending at `end` (non-inclusive) to the position starting at `target`. | ||
| ```javascript | ||
| var arr = new BooleanArray( 4 ); | ||
| arr.set( true, 0 ); | ||
| arr.set( false, 1 ); | ||
| arr.set( false, 2 ); | ||
| arr.set( true, 3 ); | ||
| var v = arr.get( 0 ); | ||
| // returns true | ||
| v = arr.get( 1 ); | ||
| // returns false | ||
| // Copy the last two elements to the first two elements: | ||
| arr.copyWithin( 0, 2 ); | ||
| v = arr.get( 0 ); | ||
| // returns false | ||
| v = arr.get( 1 ); | ||
| // returns true | ||
| ``` | ||
| By default, `end` equals the number of array elements (i.e., one more than the last array index). To limit the sequence length, provide an `end` argument. | ||
| ```javascript | ||
| var arr = new BooleanArray( 4 ); | ||
| arr.set( true, 0 ); | ||
| arr.set( false, 1 ); | ||
| arr.set( false, 2 ); | ||
| arr.set( true, 3 ); | ||
| var v = arr.get( 2 ); | ||
| // returns false | ||
| v = arr.get( 3 ); | ||
| // returns true | ||
| // Copy the first two elements to the last two elements: | ||
| arr.copyWithin( 2, 0, 2 ); | ||
| v = arr.get( 2 ); | ||
| // returns true | ||
| v = arr.get( 3 ); | ||
| // returns false | ||
| ``` | ||
| When a `target`, `start`, and/or `end` index is negative, the respective index is determined relative to the last array element. The following example achieves the same behavior as the previous example: | ||
| ```javascript | ||
| var arr = new BooleanArray( 4 ); | ||
| arr.set( true, 0 ); | ||
| arr.set( false, 1 ); | ||
| arr.set( false, 2 ); | ||
| arr.set( true, 3 ); | ||
| var v = arr.get( 2 ); | ||
| // returns false | ||
| v = arr.get( 3 ); | ||
| // returns true | ||
| // Copy the first two elements to the last two elements using negative indices: | ||
| arr.copyWithin( -2, -4, -2 ); | ||
| v = arr.get( 2 ); | ||
| // returns true | ||
| v = arr.get( 3 ); | ||
| // returns false | ||
| ``` | ||
| <a name="method-entries"></a> | ||
| #### BooleanArray.prototype.entries() | ||
| Returns an iterator for iterating over array key-value pairs. | ||
| ```javascript | ||
| var arr = new BooleanArray( 3 ); | ||
| arr.set( true, 0 ); | ||
| arr.set( false, 1 ); | ||
| arr.set( true, 2 ); | ||
| var it = arr.entries(); | ||
| var v = it.next().value; | ||
| // returns [ 0, true ] | ||
| v = it.next().value; | ||
| // returns [ 1, false ] | ||
| v = it.next().value; | ||
| // returns [ 2, true ] | ||
| var bool = it.next().done; | ||
| // returns true | ||
| ``` | ||
| The returned [iterator][mdn-iterator-protocol] protocol-compliant object has the following properties: | ||
| - **next**: function which returns an [iterator][mdn-iterator-protocol] protocol-compliant object containing the next iterated value (if one exists) assigned to a `value` property and a `done` property having a `boolean` value indicating whether the [iterator][mdn-iterator-protocol] is finished. | ||
| - **return**: function which closes an [iterator][mdn-iterator-protocol] and returns a single (optional) argument in an [iterator][mdn-iterator-protocol] protocol-compliant object. | ||
| <a name="method-every"></a> | ||
| #### BooleanArray.prototype.every( predicate\[, thisArg] ) | ||
| Returns a boolean indicating whether all elements pass a test. | ||
| ```javascript | ||
| function predicate( v ) { | ||
| return v === true; | ||
| } | ||
| var arr = new BooleanArray( 3 ); | ||
| arr.set( true, 0 ); | ||
| arr.set( true, 1 ); | ||
| arr.set( true, 2 ); | ||
| var bool = arr.every( predicate ); | ||
| // returns true | ||
| ``` | ||
| The `predicate` function is provided three arguments: | ||
| - **value**: current array element. | ||
| - **index**: current array element index. | ||
| - **arr**: the array on which this method was called. | ||
| To set the function execution context, provide a `thisArg`. | ||
| ```javascript | ||
| function predicate( v ) { | ||
| this.count += 1; | ||
| return v === true; | ||
| } | ||
| var arr = new BooleanArray( 3 ); | ||
| var context = { | ||
| 'count': 0 | ||
| }; | ||
| arr.set( true, 0 ); | ||
| arr.set( true, 1 ); | ||
| arr.set( true, 2 ); | ||
| var bool = arr.every( predicate, context ); | ||
| // returns true | ||
| var count = context.count; | ||
| // returns 3 | ||
| ``` | ||
| <a name="method-fill"></a> | ||
| #### BooleanArray.prototype.fill( value\[, start\[, end]] ) | ||
| Returns a modified typed array filled with a fill value. | ||
| ```javascript | ||
| var arr = new BooleanArray( 3 ); | ||
| // Set all elements to the same value: | ||
| arr.fill( true ); | ||
| var v = arr.get( 0 ); | ||
| // returns true | ||
| v = arr.get( 1 ); | ||
| // returns true | ||
| v = arr.get( 2 ); | ||
| // returns true | ||
| // Fill all elements starting from the second element: | ||
| arr.fill( false, 1 ); | ||
| v = arr.get( 1 ); | ||
| // returns false | ||
| v = arr.get( 2 ); | ||
| // returns false | ||
| // Fill all elements from first element until the second-to-last element: | ||
| arr.fill( false, 0, 2 ); | ||
| v = arr.get( 0 ); | ||
| // returns false | ||
| v = arr.get( 1 ); | ||
| // returns false | ||
| ``` | ||
| When a `start` and/or `end` index is negative, the respective index is determined relative to the last array element. | ||
| ```javascript | ||
| var arr = new BooleanArray( 3 ); | ||
| // Set all array elements, except the last element, to the same value: | ||
| arr.fill( true, 0, -1 ); | ||
| var v = arr.get( 0 ); | ||
| // returns true | ||
| v = arr.get( 2 ); | ||
| // returns false | ||
| ``` | ||
| <a name="method-filter"></a> | ||
| #### BooleanArray.prototype.filter( predicate\[, thisArg] ) | ||
| Returns a new array containing the elements of an array which pass a test implemented by a predicate function. | ||
| ```javascript | ||
| function predicate( v ) { | ||
| return ( v === true ); | ||
| } | ||
| var arr = new BooleanArray( 3 ); | ||
| // Set the first three elements: | ||
| arr.set( true, 0 ); | ||
| arr.set( false, 1 ); | ||
| arr.set( true, 2 ); | ||
| var out = arr.filter( predicate ); | ||
| // returns <BooleanArray> | ||
| var len = out.length; | ||
| // returns 2 | ||
| var v = out.get( 0 ); | ||
| // returns true | ||
| v = out.get( 1 ); | ||
| // return true | ||
| ``` | ||
| The `predicate` function is provided three arguments: | ||
| - **value**: current array element. | ||
| - **index**: current array element index. | ||
| - **arr**: the array on which this method was called. | ||
| To set the function execution context, provide a `thisArg`. | ||
| ```javascript | ||
| function predicate( v, i ) { | ||
| this.count += 1; | ||
| return ( v === true ); | ||
| } | ||
| var arr = new BooleanArray( 3 ); | ||
| var context = { | ||
| 'count': 0 | ||
| }; | ||
| arr.set( true, 0 ); | ||
| arr.set( false, 1 ); | ||
| arr.set( true, 2 ); | ||
| var out = arr.filter( predicate, context ); | ||
| // returns <BooleanArray> | ||
| var len = out.length; | ||
| // returns 2 | ||
| var count = context.count; | ||
| // returns 3 | ||
| ``` | ||
| <a name="method-find"></a> | ||
@@ -467,3 +786,3 @@ | ||
| #### Complex64Array.prototype.findLast( predicate\[, thisArg] ) | ||
| #### BooleanArray.prototype.findLast( predicate\[, thisArg] ) | ||
@@ -570,2 +889,62 @@ Returns the last element in an array for which a predicate function returns a truthy value. | ||
| <a name="method-for-each"></a> | ||
| #### BooleanArray.prototype.forEach( callbackFn\[, thisArg] ) | ||
| Invokes a function once for each array element. | ||
| ```javascript | ||
| function log( v, i ) { | ||
| console.log( '%s: %s', i, v.toString() ); | ||
| } | ||
| var arr = new BooleanArray( 3 ); | ||
| arr.set( true, 0 ); | ||
| arr.set( false, 1 ); | ||
| arr.set( true, 2 ); | ||
| arr.forEach( log ); | ||
| /* => | ||
| 0: true | ||
| 1: false | ||
| 2: true | ||
| */ | ||
| ``` | ||
| The invoked function is provided three arguments: | ||
| - **value**: current array element. | ||
| - **index**: current array element index. | ||
| - **arr**: the array on which this method was called. | ||
| To set the function execution context, provide a `thisArg`. | ||
| ```javascript | ||
| function fcn( v, i ) { | ||
| this.count += 1; | ||
| console.log( '%s: %s', i, v.toString() ); | ||
| } | ||
| var arr = new BooleanArray( 3 ); | ||
| var context = { | ||
| 'count': 0 | ||
| }; | ||
| arr.set( true, 0 ); | ||
| arr.set( false, 1 ); | ||
| arr.set( true, 2 ); | ||
| arr.forEach( fcn, context ); | ||
| /* => | ||
| 0: 1 + 1i | ||
| 1: 2 + 2i | ||
| 2: 3 + 3i | ||
| */ | ||
| var count = context.count; | ||
| // returns 3 | ||
| ``` | ||
| <a name="method-get"></a> | ||
@@ -597,2 +976,159 @@ | ||
| <a name="includes"></a> | ||
| #### BooleanArray.prototype.includes( searchElement\[, fromIndex] ) | ||
| Returns a boolean indicating whether an array includes a provided value. | ||
| ```javascript | ||
| var arr = new BooleanArray( 5 ); | ||
| arr.set( true, 0 ); | ||
| arr.set( false, 1 ); | ||
| arr.set( true, 2 ); | ||
| arr.set( true, 3 ); | ||
| arr.set( true, 4 ); | ||
| var bool = arr.includes( true ); | ||
| // returns true | ||
| bool = arr.includes( false, 2 ); | ||
| // returns false | ||
| ``` | ||
| <a name="method-index-of"></a> | ||
| #### BooleanArray.prototype.indexOf( searchElement\[, fromIndex] ) | ||
| Returns the first index at which a given element can be found. | ||
| ```javascript | ||
| var arr = new BooleanArray( 5 ); | ||
| arr.set( true, 0 ); | ||
| arr.set( false, 1 ); | ||
| arr.set( true, 2 ); | ||
| arr.set( true, 3 ); | ||
| arr.set( true, 4 ); | ||
| var idx = arr.indexOf( true ); | ||
| // returns 0 | ||
| idx = arr.indexOf( false, 1 ); | ||
| // returns 1 | ||
| idx = arr.indexOf( true, -3 ); | ||
| // returns 2 | ||
| ``` | ||
| If `searchElement` is not present in the array, the method returns `-1`. | ||
| ```javascript | ||
| var arr = new BooleanArray( 3 ); | ||
| arr.set( true, 0 ); | ||
| arr.set( true, 1 ); | ||
| arr.set( true, 2 ); | ||
| var idx = arr.indexOf( false ); | ||
| // returns -1 | ||
| ``` | ||
| <a name="join"></a> | ||
| #### BooleanArray.prototype.join( \[separator] ) | ||
| Returns a new string by concatenating all array elements. | ||
| ```javascript | ||
| var arr = new BooleanArray( 3 ); | ||
| arr.set( true, 0 ); | ||
| arr.set( false, 1 ); | ||
| arr.set( true, 2 ); | ||
| var str = arr.join(); | ||
| // returns 'true,false,true' | ||
| ``` | ||
| By default, the method separates serialized array elements with a comma. To use an alternative separator, provide a `separator` string. | ||
| ```javascript | ||
| var arr = new BooleanArray( 3 ); | ||
| arr.set( true, 0 ); | ||
| arr.set( false, 1 ); | ||
| arr.set( true, 2 ); | ||
| var str = arr.join( '|' ); | ||
| // returns 'true|false|true' | ||
| ``` | ||
| <a name="method-keys"></a> | ||
| #### BooleanArray.prototype.keys() | ||
| Returns an iterator for iterating over each index key in a typed array. | ||
| ```javascript | ||
| var arr = new BooleanArray( 2 ); | ||
| arr.set( true, 0 ); | ||
| arr.set( false, 1 ); | ||
| var iter = arr.keys(); | ||
| var v = iter.next().value; | ||
| // returns 0 | ||
| v = iter.next().value; | ||
| // returns 1 | ||
| var bool = iter.next().done; | ||
| // returns true | ||
| ``` | ||
| The returned [iterator][mdn-iterator-protocol] protocol-compliant object has the following properties: | ||
| - **next**: function which returns an [iterator][mdn-iterator-protocol] protocol-compliant object containing the next iterated value (if one exists) assigned to a `value` property and a `done` property having a `boolean` value indicating whether the [iterator][mdn-iterator-protocol] is finished. | ||
| - **return**: function which closes an [iterator][mdn-iterator-protocol] and returns a single (optional) argument in an [iterator][mdn-iterator-protocol] protocol-compliant object. | ||
| <a name="method-last-index-of"></a> | ||
| #### BooleanArray.prototype.lastIndexOf( searchElement\[, fromIndex] ) | ||
| Returns the last index at which a given element can be found. | ||
| ```javascript | ||
| var arr = new BooleanArray( 5 ); | ||
| arr.set( true, 0 ); | ||
| arr.set( true, 1 ); | ||
| arr.set( true, 2 ); | ||
| arr.set( false, 3 ); | ||
| arr.set( true, 4 ); | ||
| var idx = arr.lastIndexOf( true ); | ||
| // returns 4 | ||
| idx = arr.lastIndexOf( false, 3 ); | ||
| // returns 3 | ||
| idx = arr.lastIndexOf( true, -3 ); | ||
| // returns 2 | ||
| ``` | ||
| If `searchElement` is not present in the array, the method returns `-1`. | ||
| ```javascript | ||
| var arr = new BooleanArray( 3 ); | ||
| arr.set( true, 0 ); | ||
| arr.set( true, 1 ); | ||
| arr.set( true, 2 ); | ||
| var idx = arr.lastIndexOf( false ); | ||
| // returns -1 | ||
| ``` | ||
| <a name="method-map"></a> | ||
@@ -659,2 +1195,98 @@ | ||
| <a name="method-reduce"></a> | ||
| #### BooleanArray.prototype.reduce( reducerFn\[, initialValue] ) | ||
| Applies a provided callback function to each element of the array, in order, passing in the return value from the calculation on the preceding element and returning the accumulated result upon completion. | ||
| ```javascript | ||
| function reducer( acc, v ) { | ||
| return ( acc && v ); | ||
| } | ||
| var arr = new BooleanArray( 3 ); | ||
| arr.set( true, 0 ); | ||
| arr.set( false, 1 ); | ||
| arr.set( true, 2 ); | ||
| var out = arr.reduce( reducer ); | ||
| // returns false | ||
| ``` | ||
| The reducer function is provided four arguments: | ||
| - **acc**: accumulated result. | ||
| - **value**: current array element. | ||
| - **index**: current array element index. | ||
| - **arr**: the array on which this method was called. | ||
| By default, the function initializes the accumulated result to the first element in the array and passes the second array element as `value` during the first invocation of the provided callback. To begin accumulation from a different starting value and pass in the first array element as `value` during the first invocation of the provided callback, provide an `initialValue` argument. | ||
| ```javascript | ||
| function reducer( acc, v ) { | ||
| if ( v ) { | ||
| return acc + 1; | ||
| } | ||
| return acc; | ||
| } | ||
| var arr = new BooleanArray( 3 ); | ||
| arr.set( true, 0 ); | ||
| arr.set( false, 1 ); | ||
| arr.set( true, 2 ); | ||
| var out = arr.reduce( reducer, 0 ); | ||
| // returns 2 | ||
| ``` | ||
| <a name="method-reduce-right"></a> | ||
| #### BooleanArray.prototype.reduceRight( reducerFn\[, initialValue] ) | ||
| Applies a provided callback function to each element of the array, in reverse order, passing in the return value from the calculation on the following element and returning the accumulated result upon completion. | ||
| ```javascript | ||
| function reducer( acc, v ) { | ||
| return ( acc && v ); | ||
| } | ||
| var arr = new BooleanArray( 3 ); | ||
| arr.set( true, 0 ); | ||
| arr.set( false, 1 ); | ||
| arr.set( true, 2 ); | ||
| var out = arr.reduceRight( reducer ); | ||
| // returns false | ||
| ``` | ||
| The reducer function is provided four arguments: | ||
| - **acc**: accumulated result. | ||
| - **value**: current array element. | ||
| - **index**: current array element index. | ||
| - **arr**: the array on which this method was called. | ||
| By default, the function initializes the accumulated result to the last element in the array and passes the second-last array element as `value` during the first invocation of the provided callback. To begin accumulation from a different starting value and pass in the last array element as `value` during the first invocation of the provided callback, provide an `initialValue` argument. | ||
| ```javascript | ||
| function reducer( acc, v ) { | ||
| if ( v ) { | ||
| return acc + 1; | ||
| } | ||
| return acc; | ||
| } | ||
| var arr = new BooleanArray( 3 ); | ||
| arr.set( true, 0 ); | ||
| arr.set( false, 1 ); | ||
| arr.set( true, 2 ); | ||
| var out = arr.reduceRight( reducer, 0 ); | ||
| // returns 2 | ||
| ``` | ||
| <a name="method-reverse"></a> | ||
@@ -746,2 +1378,130 @@ | ||
| <a name="method-slice"></a> | ||
| #### BooleanArray.prototype.slice( \[start\[, end]] ) | ||
| Copies a portion of a typed array to a new typed array. | ||
| ```javascript | ||
| var arr = new BooleanArray( 5 ); | ||
| arr.set( true, 0 ); | ||
| arr.set( false, 1 ); | ||
| arr.set( true, 2 ); | ||
| arr.set( false, 3 ); | ||
| arr.set( true, 4 ); | ||
| var out = arr.slice(); | ||
| // returns <BooleanArray> | ||
| var len = out.length; | ||
| // returns 5 | ||
| var bool = out.get( 0 ); | ||
| // returns true | ||
| bool = out.get( len-1 ); | ||
| // returns true | ||
| ``` | ||
| By default, the method returns a typed array beginning with the first array element. To specify an alternative array index at which to begin, provide a `start` index (inclusive). | ||
| ```javascript | ||
| var arr = new BooleanArray( 5 ); | ||
| arr.set( true, 0 ); | ||
| arr.set( false, 1 ); | ||
| arr.set( true, 2 ); | ||
| arr.set( false, 3 ); | ||
| arr.set( true, 4 ); | ||
| var out = arr.slice( 1 ); | ||
| // returns <BooleanArray> | ||
| var len = out.length; | ||
| // returns 4 | ||
| var bool = out.get( 0 ); | ||
| // returns false | ||
| bool = out.get( len-1 ); | ||
| // returns true | ||
| ``` | ||
| By default, the method returns a typed array which includes all array elements after `start`. To limit the number of array elements after `start`, provide an `end` index (exclusive). | ||
| ```javascript | ||
| var arr = new BooleanArray( 5 ); | ||
| arr.set( true, 0 ); | ||
| arr.set( false, 1 ); | ||
| arr.set( true, 2 ); | ||
| arr.set( false, 3 ); | ||
| arr.set( true, 4 ); | ||
| var out = arr.slice( 1, -2 ); | ||
| // returns <BooleanArray> | ||
| var len = out.length; | ||
| // returns 2 | ||
| var bool = out.get( 0 ); | ||
| // returns false | ||
| bool = out.get( len-1 ); | ||
| // returns true | ||
| ``` | ||
| <a name="method-some"></a> | ||
| #### BooleanArray.prototype.some( predicate\[, thisArg] ) | ||
| Returns a boolean indicating whether at least one element passes a test. | ||
| ```javascript | ||
| function predicate( v ) { | ||
| return v === true; | ||
| } | ||
| var arr = new BooleanArray( 3 ); | ||
| arr.set( false, 0 ); | ||
| arr.set( true, 1 ); | ||
| arr.set( false, 2 ); | ||
| var bool = arr.some( predicate ); | ||
| // returns true | ||
| ``` | ||
| The `predicate` function is provided three arguments: | ||
| - **value**: current array element. | ||
| - **index**: current array element index. | ||
| - **arr**: the array on which this method was called. | ||
| To set the function execution context, provide a `thisArg`. | ||
| ```javascript | ||
| function predicate( v ) { | ||
| this.count += 1; | ||
| return v === true; | ||
| } | ||
| var arr = new BooleanArray( 3 ); | ||
| var context = { | ||
| 'count': 0 | ||
| }; | ||
| arr.set( false, 0 ); | ||
| arr.set( true, 1 ); | ||
| arr.set( false, 2 ); | ||
| var bool = arr.some( predicate, context ); | ||
| // returns true | ||
| var count = context.count; | ||
| // returns 2 | ||
| ``` | ||
| <a name="method-sort"></a> | ||
@@ -796,2 +1556,100 @@ | ||
| <a name="method-subarray"></a> | ||
| #### BooleanArray.prototype.subarray( \[begin\[, end]] ) | ||
| Creates a new typed array view over the same underlying [`ArrayBuffer`][@stdlib/array/buffer] and with the same underlying data type as the host array. | ||
| ```javascript | ||
| var arr = new BooleanArray( 5 ); | ||
| arr.set( true, 0 ); | ||
| arr.set( false, 1 ); | ||
| arr.set( true, 2 ); | ||
| arr.set( false, 3 ); | ||
| arr.set( true, 4 ); | ||
| var subarr = arr.subarray(); | ||
| // returns <BooleanArray> | ||
| var len = subarr.length; | ||
| // returns 5 | ||
| var bool = subarr.get( 0 ); | ||
| // returns true | ||
| bool = subarr.get( len-1 ); | ||
| // returns true | ||
| ``` | ||
| By default, the method creates a typed array view beginning with the first array element. To specify an alternative array index at which to begin, provide a `begin` index (inclusive). | ||
| ```javascript | ||
| var arr = new BooleanArray( 5 ); | ||
| arr.set( true, 0 ); | ||
| arr.set( false, 1 ); | ||
| arr.set( true, 2 ); | ||
| arr.set( false, 3 ); | ||
| arr.set( true, 4 ); | ||
| var subarr = arr.subarray( 1 ); | ||
| // returns <BooleanArray> | ||
| var len = subarr.length; | ||
| // returns 4 | ||
| var bool = subarr.get( 0 ); | ||
| // returns false | ||
| bool = subarr.get( len-1 ); | ||
| // returns true | ||
| ``` | ||
| By default, the method creates a typed array view which includes all array elements after `begin`. To limit the number of array elements after `begin`, provide an `end` index (exclusive). | ||
| ```javascript | ||
| var arr = new BooleanArray( 5 ); | ||
| arr.set( true, 0 ); | ||
| arr.set( false, 1 ); | ||
| arr.set( true, 2 ); | ||
| arr.set( false, 3 ); | ||
| arr.set( true, 4 ); | ||
| var subarr = arr.subarray( 1, -2 ); | ||
| // returns <BooleanArray> | ||
| var len = subarr.length; | ||
| // returns 2 | ||
| var bool = subarr.get( 0 ); | ||
| // returns false | ||
| bool = subarr.get( len-1 ); | ||
| // returns true | ||
| ``` | ||
| <a name="method-to-locale-string"></a> | ||
| #### BooleanArray.prototype.toLocaleString( \[locales\[, options]] ) | ||
| Serializes an array as a locale-specific string. | ||
| ```javascript | ||
| var arr = new BooleanArray( 3 ); | ||
| arr.set( true, 0 ); | ||
| arr.set( false, 1 ); | ||
| arr.set( true, 2 ); | ||
| var str = arr.toLocaleString(); | ||
| // returns 'true,false,true' | ||
| ``` | ||
| The method supports the following arguments: | ||
| - **locales**: a string with a BCP 47 language tag or an array of such strings. | ||
| - **options**: configuration properties. | ||
| <a name="method-to-reversed"></a> | ||
@@ -823,2 +1681,118 @@ | ||
| <a name="method-to-sorted"></a> | ||
| #### BooleanArray.prototype.toSorted( \[compareFcn] ) | ||
| Returns a new typed array containing the elements in sorted order. | ||
| ```javascript | ||
| function compare( a, b ) { | ||
| if ( a === false ) { | ||
| if ( b === false ) { | ||
| return 0; | ||
| } | ||
| return 1; | ||
| } | ||
| if ( b === true ) { | ||
| return 0; | ||
| } | ||
| return -1; | ||
| } | ||
| var arr = new BooleanArray( 3 ); | ||
| arr.set( true, 0 ); | ||
| arr.set( false, 1 ); | ||
| arr.set( true, 2 ); | ||
| var out = arr.sort( compare ); | ||
| // returns <BooleanArray> | ||
| var v = out.get( 0 ); | ||
| // returns true | ||
| v = out.get( 1 ); | ||
| // returns true | ||
| v = out.get( 2 ); | ||
| // returns false | ||
| ``` | ||
| The `compareFcn` determines the order of the elements. The function is called with the following arguments: | ||
| - **a**: the first boolean value for comparison. | ||
| - **b**: the second boolean value for comparison. | ||
| The function should return a number where: | ||
| - a negative value indicates that `a` should come before `b`. | ||
| - a positive value indicates that `a` should come after `b`. | ||
| - zero or `NaN` indicates that `a` and `b` are considered equal. | ||
| <a name="method-to-string"></a> | ||
| #### BooleanArray.prototype.toString() | ||
| Serializes an array as a string. | ||
| ```javascript | ||
| var arr = new BooleanArray( 3 ); | ||
| arr.set( true, 0 ); | ||
| arr.set( false, 1 ); | ||
| arr.set( true, 2 ); | ||
| var str = arr.toString(); | ||
| // returns 'true,false,true' | ||
| ``` | ||
| <a name="method-values"></a> | ||
| #### BooleanArray.prototype.values() | ||
| Returns an iterator for iterating over each value in a typed array. | ||
| ```javascript | ||
| var arr = new BooleanArray( 2 ); | ||
| arr.set( true, 0 ); | ||
| arr.set( false, 1 ); | ||
| var iter = arr.values(); | ||
| var v = iter.next().value; | ||
| // returns true | ||
| v = iter.next().value; | ||
| // returns false | ||
| var bool = iter.next().done; | ||
| // returns true | ||
| ``` | ||
| The returned [iterator][mdn-iterator-protocol] protocol-compliant object has the following properties: | ||
| - **next**: function which returns an [iterator][mdn-iterator-protocol] protocol-compliant object containing the next iterated value (if one exists) assigned to a `value` property and a `done` property having a `boolean` value indicating whether the [iterator][mdn-iterator-protocol] is finished. | ||
| - **return**: function which closes an [iterator][mdn-iterator-protocol] and returns a single (optional) argument in an [iterator][mdn-iterator-protocol] protocol-compliant object. | ||
| <a name="method-with"></a> | ||
| #### BooleanArray.prototype.with( index, value ) | ||
| Returns a new typed array with the element at a provided index replaced with a provided value. | ||
| ```javascript | ||
| var arr = new BooleanArray( 3 ); | ||
| arr.set( true, 0 ); | ||
| arr.set( false, 1 ); | ||
| arr.set( true, 1 ); | ||
| var out = arr.with( 0, false ); | ||
| // returns <BooleanArray> | ||
| var v = out.get( 0 ); | ||
| // returns false | ||
| ``` | ||
| </section> | ||
@@ -941,4 +1915,4 @@ | ||
| [test-image]: https://github.com/stdlib-js/array-bool/actions/workflows/test.yml/badge.svg?branch=v0.0.1 | ||
| [test-url]: https://github.com/stdlib-js/array-bool/actions/workflows/test.yml?query=branch:v0.0.1 | ||
| [test-image]: https://github.com/stdlib-js/array-bool/actions/workflows/test.yml/badge.svg?branch=v0.1.0 | ||
| [test-url]: https://github.com/stdlib-js/array-bool/actions/workflows/test.yml?query=branch:v0.1.0 | ||
@@ -975,2 +1949,4 @@ [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/array-bool/main.svg | ||
| [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol | ||
| [@stdlib/array/typed]: https://www.npmjs.com/package/@stdlib/array-typed | ||
@@ -977,0 +1953,0 @@ |
Sorry, the diff of this file is too big to display
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
272661
93.45%4126
104.36%1949
100.31%20
25%10
233.33%