@nullvoxpopuli/ember-composable-helpers
Version:
Composable helpers for Ember
18 lines (14 loc) • 428 B
text/typescript
import { helper } from '@ember/component/helper';
import { isEmpty } from '@ember/utils';
import asArray from '../utils/as-array.ts';
export function reduce<T>([callback, initialValue, array]: [
(previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T,
T,
T[],
]) {
if (isEmpty(callback)) {
return [];
}
return asArray(array).reduce(callback, initialValue);
}
export default helper(reduce);