src/lib/reduce.ts
import { is } from './is';
export const reduce = (collection, fn, memo) => {
if (is.Array(collection)) {
for (let i = 0, len = collection.length; i < len; i++) {
memo = fn(memo, collection[i], i, collection);
}
} else {
for (const key in collection) {
if ({}.hasOwnProperty.call(collection, key)) {
memo = fn(memo, collection[key], key, collection);
}
}
}
return memo;
};