needs filterMap

This commit is contained in:
Putnam3145
2022-08-07 17:32:19 -07:00
parent e1c822cbd8
commit cdaefe18f6

View File

@@ -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;