Skip to content

Commit

Permalink
types: type safer implementation for sum function (#358) (#359)
Browse files Browse the repository at this point in the history
* types: type safer implementation for `sum` (#358)

* fix checks

---------

Co-authored-by: jukanntenn <[email protected]>
  • Loading branch information
2 people authored and aleclarson committed Jun 24, 2024
1 parent 5082f9c commit 961fc75
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 20 deletions.
9 changes: 3 additions & 6 deletions cdn/radash.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,9 @@ const boil = (array, compareFunc) => {
return null;
return array.reduce(compareFunc);
};
const sum = (array, fn) => {
return (array || []).reduce(
(acc, item) => acc + (fn ? fn(item) : item),
0
);
};
function sum(array, fn) {
return (array || []).reduce((acc, item) => acc + (fn ? fn(item) : item), 0);
}
const first = (array, defaultValue = void 0) => {
return array?.length > 0 ? array[0] : defaultValue;
};
Expand Down
9 changes: 3 additions & 6 deletions cdn/radash.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,9 @@ var radash = (function (exports) {
return null;
return array.reduce(compareFunc);
};
const sum = (array, fn) => {
return (array || []).reduce(
(acc, item) => acc + (fn ? fn(item) : item),
0
);
};
function sum(array, fn) {
return (array || []).reduce((acc, item) => acc + (fn ? fn(item) : item), 0);
}
const first = (array, defaultValue = void 0) => {
return array?.length > 0 ? array[0] : defaultValue;
};
Expand Down
Loading

0 comments on commit 961fc75

Please sign in to comment.