fix(core): update
This commit is contained in:
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartarray',
|
||||
version: '1.0.4',
|
||||
description: 'a package exposing async manipulation for arrays'
|
||||
}
|
25
ts/index.ts
25
ts/index.ts
@ -1,4 +1,7 @@
|
||||
export const filter = async<T>(arrayArg: T[], filterFunction: (itemArg: T) => Promise<boolean>): Promise<T[]> => {
|
||||
export const filter = async <T>(
|
||||
arrayArg: T[],
|
||||
filterFunction: (itemArg: T) => Promise<boolean>
|
||||
): Promise<T[]> => {
|
||||
const returnArray: T[] = [];
|
||||
for (const itemArg of arrayArg) {
|
||||
const filterResult = await filterFunction(itemArg);
|
||||
@ -7,4 +10,22 @@ export const filter = async<T>(arrayArg: T[], filterFunction: (itemArg: T) => Pr
|
||||
}
|
||||
}
|
||||
return returnArray;
|
||||
}
|
||||
};
|
||||
|
||||
export const deduplicate = async <T, K>(
|
||||
arrayArg: T[],
|
||||
keyCreation: (itemArg: T) => Promise<K>
|
||||
): Promise<T[]> => {
|
||||
const keysSet: Set<K> = new Set();
|
||||
const returnArray: T[] = [];
|
||||
|
||||
for (const itemArg of arrayArg) {
|
||||
const key = await keyCreation(itemArg);
|
||||
if (!keysSet.has(key)) {
|
||||
keysSet.add(key);
|
||||
returnArray.push(itemArg);
|
||||
}
|
||||
}
|
||||
|
||||
return returnArray;
|
||||
};
|
||||
|
Reference in New Issue
Block a user