needs filterMap
This commit is contained in:
@@ -123,6 +123,26 @@ export const map = iterateeFn => collection => {
|
||||
throw new Error(`map() can't iterate on type ${typeof collection}`);
|
||||
};
|
||||
|
||||
/**
|
||||
* Given a collection, will run each element through an iteratee function.
|
||||
* Will then filter out undefined values.
|
||||
*/
|
||||
export const filterMap = <T, U>(
|
||||
collection: T[],
|
||||
iterateeFn: (value: T) => U | undefined
|
||||
): U[] => {
|
||||
const finalCollection: U[] = [];
|
||||
|
||||
for (const value of collection) {
|
||||
const output = iterateeFn(value);
|
||||
if (output !== undefined) {
|
||||
finalCollection.push(output);
|
||||
}
|
||||
}
|
||||
|
||||
return finalCollection;
|
||||
};
|
||||
|
||||
const COMPARATOR = (objA, objB) => {
|
||||
const criteriaA = objA.criteria;
|
||||
const criteriaB = objB.criteria;
|
||||
|
||||
Reference in New Issue
Block a user