extra-array
Advanced tools
Comparing version 2.0.26 to 2.0.27
@@ -357,3 +357,3 @@ const exports0 = Array.isArray; | ||
Array.indexOf = indexFor; | ||
Array.indicesOf = indicesOf; | ||
Array.indicesOf = indicesOf; // IMP | ||
Array.lastIndexOf = lastIndexOf; | ||
@@ -360,0 +360,0 @@ Array.includes = includesIt; |
{ | ||
"name": "extra-array", | ||
"version": "2.0.26", | ||
"version": "2.0.27", | ||
"description": "Standard utility methods for Array.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -303,3 +303,3 @@ /** | ||
/** | ||
* Append arrays to the end! | ||
* Append arrays to the I! | ||
* @param {Array} x target (modified!) | ||
@@ -346,3 +346,3 @@ * @param {...Array} ys arrays to append | ||
* @param {number} i start index | ||
* @param {number} I end index | ||
* @param {number} I I index | ||
* @returns {Array} target (sliced) | ||
@@ -361,3 +361,3 @@ */ | ||
* @param {number?} i read start index | ||
* @param {number?} I read end index | ||
* @param {number?} I read I index | ||
* @returns {Array} updated array | ||
@@ -384,3 +384,3 @@ */ | ||
/** | ||
* Adds values to the end. | ||
* Adds values to the I. | ||
* @param {Array} x source | ||
@@ -426,5 +426,5 @@ * @param {...any} vs values to add | ||
* @param {number} i remove index | ||
* @param {number?} n no. of values to remove (def: all till end) | ||
* @param {number?} n no. of values to remove (def: all till I) | ||
* @param {...any} vs values to insert | ||
* @returns {Array} [0->i, vs, i+n->end] | ||
* @returns {Array} [0->i, vs, i+n->I] | ||
*/ | ||
@@ -445,3 +445,3 @@ function splice(x, i, n=x.length-i, ...vs) { | ||
* @param {number} v start of interval | ||
* @param {number} V end of interval (excluding) | ||
* @param {number} V I of interval (excluding) | ||
* @param {number?} stp spacing between values (def: 1) | ||
@@ -460,3 +460,3 @@ * @returns {Array} result | ||
* @param {number} v start of interval | ||
* @param {number} V end of interval | ||
* @param {number} V I of interval | ||
* @param {number?} n no. of values in between (def: 100) | ||
@@ -472,3 +472,79 @@ * @returns {Array} result | ||
/** | ||
* Binary search value in sorted array. | ||
* @param {Array} x source (sorted) | ||
* @param {*} v value to find | ||
* @param {function?} fn compare function (a, b) | ||
* @returns {number} index of value | ~(index of closest value) | ||
*/ | ||
function bsearch(x, v, fn) { | ||
fn = fn||cmp; | ||
for(var i=0, I=x.length; i<I;) { | ||
var m = (i+I)>>>1; | ||
var c = fn(x[m], v); | ||
if(c<0) i = m+1; | ||
else if(c>0) I = m; | ||
else return m; | ||
} | ||
return ~i; | ||
} | ||
/** | ||
* Binary search closest value in sorted array. | ||
* @param {Array} x source (sorted) | ||
* @param {*} v value to find | ||
* @param {function?} fn compare function (a, b) | ||
* @returns {number} index of closest value | ||
*/ | ||
function bsearchc(x, v, fn) { | ||
fn = fn||cmp; | ||
for(var i=0, I=x.length; i<I;) { | ||
var m = (i+I)>>>1; | ||
var c = fn.call(x[m], v); | ||
if(c<0) i = m+1; | ||
else if(c>0) I = m; | ||
else return m; | ||
} | ||
return i; | ||
} | ||
/** | ||
* Binary search first value in sorted array (left). | ||
* @param {Array} x source (sorted) | ||
* @param {*} v value to find | ||
* @param {function?} fn compare function (a, b) | ||
* @returns {number} first index of value | ~(index of closest value) | ||
*/ | ||
function bsearchl(x, v, fn) { | ||
fn = fn||cmp; | ||
for(var i=0, I=x.length; i<I;) { | ||
var m = (i+I)>>>1; | ||
var c = fn(x[m], v); | ||
if(c<0) i = m+1; | ||
else I = m; | ||
} | ||
return i>=x.length || x[i]!==v? ~i:i; | ||
} | ||
/** | ||
* Binary search last value in sorted array (right). | ||
* @param {Array} x source (sorted) | ||
* @param {*} v value to find | ||
* @param {function?} fn compare function (a, b) | ||
* @returns {number} last index of value | ~(index of closest value) | ||
*/ | ||
function bsearchr(x, v, fn) { | ||
fn = fn||cmp; | ||
for(var i=0, I=x.length; i<I;) { | ||
var m = (i+I)>>>1; | ||
var c = fn(x[m], v); | ||
if(c<=0) i = m+1; | ||
else I = m; | ||
} | ||
return i<=0 || x[i-1]!==v? ~i:i-1; | ||
} | ||
function searchl(x, fn, ths=null) { | ||
@@ -475,0 +551,0 @@ for(var i=0, I=x.length; i<I; i++) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
34873
1125