appolo-utils
Advanced tools
Comparing version 0.0.36 to 0.0.37
@@ -75,4 +75,21 @@ "use strict"; | ||
} | ||
static uniqBy(arr, criteria) { | ||
let dic = new Map(), out = []; | ||
if (!arr || !arr.length) { | ||
return []; | ||
} | ||
for (let i = 0; i < arr.length; i++) { | ||
let item = arr[i], key = criteria(item, i); | ||
if (!dic.has(key)) { | ||
dic.set(key, 1); | ||
out.push(item); | ||
} | ||
} | ||
return out; | ||
} | ||
static uniq(arr) { | ||
return Arrays.uniqBy(arr, (item) => item); | ||
} | ||
} | ||
exports.Arrays = Arrays; | ||
//# sourceMappingURL=arrays.js.map |
@@ -110,2 +110,23 @@ import {Classes} from "./classes"; | ||
} | ||
public static uniqBy<T>(arr: T[], criteria: (value: T, i?: number) => any): T[] { | ||
let dic = new Map<any, 1>(), out = []; | ||
if (!arr || !arr.length) { | ||
return [] | ||
} | ||
for (let i = 0; i < arr.length; i++) { | ||
let item = arr[i], key = criteria(item, i); | ||
if (!dic.has(key)) { | ||
dic.set(key, 1); | ||
out.push(item) | ||
} | ||
} | ||
return out; | ||
} | ||
public static uniq<T>(arr: T[]): T[] { | ||
return Arrays.uniqBy(arr, (item) => item) | ||
} | ||
} |
@@ -17,3 +17,3 @@ { | ||
"main": "./index.js", | ||
"version": "0.0.36", | ||
"version": "0.0.37", | ||
"license": "MIT", | ||
@@ -20,0 +20,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
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
82389
1475