From 29da4d0a1fa79c6b0d7db226d981f6ea1f246e33 Mon Sep 17 00:00:00 2001 From: haoziqaq <357229046@qq.com> Date: Sun, 8 Dec 2024 03:15:15 +0800 Subject: [PATCH] types: improve maxBy minBy types --- src/math/maxBy.ts | 4 ---- src/math/minBy.ts | 4 ---- 2 files changed, 8 deletions(-) diff --git a/src/math/maxBy.ts b/src/math/maxBy.ts index d5ffce6..9fcd8cf 100644 --- a/src/math/maxBy.ts +++ b/src/math/maxBy.ts @@ -1,7 +1,3 @@ export function maxBy(arr: T[], fn: (val: T) => number) { - if (!arr.length) { - return - } - return arr.reduce((result, item) => (fn(result) > fn(item) ? result : item), arr[0]) } diff --git a/src/math/minBy.ts b/src/math/minBy.ts index 4496be7..f9386a7 100644 --- a/src/math/minBy.ts +++ b/src/math/minBy.ts @@ -1,7 +1,3 @@ export function minBy(arr: T[], fn: (val: T) => number) { - if (!arr.length) { - return - } - return arr.reduce((result, item) => (fn(result) < fn(item) ? result : item), arr[0]) }