extra-array
Advanced tools
Comparing version 2.0.27 to 2.0.28
15
fresh.js
@@ -152,17 +152,2 @@ // PURE FUNCTIONS | ||
/** | ||
* Removes duplicate elements. | ||
* @param {Array} x array | ||
* @param {function} fn compare function (a, b) | ||
* @returns {Array} unique element array | ||
*/ | ||
function nub(x, fn) { | ||
var a = []; | ||
x: for(var e of x) { | ||
for(var f of a) | ||
if(fn(e, f)===0) continue x; | ||
a.push(e); | ||
} | ||
return a; | ||
} | ||
@@ -169,0 +154,0 @@ /** |
{ | ||
"name": "extra-array", | ||
"version": "2.0.27", | ||
"version": "2.0.28", | ||
"description": "Standard utility methods for Array.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -303,3 +303,3 @@ /** | ||
/** | ||
* Append arrays to the I! | ||
* Append arrays to the end! | ||
* @param {Array} x target (modified!) | ||
@@ -382,3 +382,3 @@ * @param {...Array} ys arrays to append | ||
/** | ||
* Adds values to the I. | ||
* Adds values to the end. | ||
* @param {Array} x source | ||
@@ -543,3 +543,40 @@ * @param {...any} vs values to add | ||
/** | ||
* Removes duplicate elements. | ||
* @param {Array} x source | ||
* @param {function?} fn compare function (a, b) | ||
* @returns {Array} unique valued array | ||
*/ | ||
function nub(x, fn) { | ||
if(!fn) return Array.from(new Set(x)); | ||
var a = []; | ||
x: for(var v of x) { | ||
for(var w of a) | ||
if(fn(v, w)===0) continue x; | ||
a.push(v); | ||
} | ||
return a; | ||
} | ||
/** | ||
* Removes duplicate elements based of map function (once per value). | ||
* @param {Array} x source | ||
* @param {function} fn map function (v, i, x) | ||
* @param {object?} ths this argument | ||
* @returns {Array} unique valued array | ||
*/ | ||
function nubOn(x, fn, ths=null) { | ||
var m = new Map(), i = -1; | ||
for(var v of x) { | ||
var w = fn.call(ths, v, ++i, x); | ||
if(!m.has(w)) m.set(w, v); | ||
} | ||
return Array.from(m.values()); | ||
} | ||
function searchl(x, fn, ths=null) { | ||
@@ -546,0 +583,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
35345
1141