From d0625f4b19ba84d0c7c7e730925f3d88bf10b694 Mon Sep 17 00:00:00 2001 From: D-Sketon <2055272094@qq.com> Date: Sun, 15 Dec 2024 21:10:06 +0800 Subject: [PATCH 1/4] fix: should handle keys like toString or valueOf --- src/array/groupBy.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/array/groupBy.ts b/src/array/groupBy.ts index 797e4a1ae..a3889f7ea 100644 --- a/src/array/groupBy.ts +++ b/src/array/groupBy.ts @@ -37,7 +37,7 @@ export function groupBy(arr: readonly T[], getKeyFromI const item = arr[i]; const key = getKeyFromItem(item); - if (result[key] == null) { + if (!result.hasOwnProperty(key) || result[key] == null) { result[key] = []; } From 76fbc26c2ce613cf0e3369155ad74ba51fb04429 Mon Sep 17 00:00:00 2001 From: D-Sketon <2055272094@qq.com> Date: Sun, 15 Dec 2024 21:13:42 +0800 Subject: [PATCH 2/4] make lint happy --- src/array/groupBy.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/array/groupBy.ts b/src/array/groupBy.ts index a3889f7ea..b33a96a01 100644 --- a/src/array/groupBy.ts +++ b/src/array/groupBy.ts @@ -37,7 +37,7 @@ export function groupBy(arr: readonly T[], getKeyFromI const item = arr[i]; const key = getKeyFromItem(item); - if (!result.hasOwnProperty(key) || result[key] == null) { + if (!Object.prototype.hasOwnProperty.call(result, key) || result[key] == null) { result[key] = []; } From 48a823d08acc08f47afe53f263c986c16909375d Mon Sep 17 00:00:00 2001 From: D-Sketon <2055272094@qq.com> Date: Sun, 15 Dec 2024 21:17:10 +0800 Subject: [PATCH 3/4] make lint happy --- src/array/groupBy.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/array/groupBy.ts b/src/array/groupBy.ts index b33a96a01..09979741a 100644 --- a/src/array/groupBy.ts +++ b/src/array/groupBy.ts @@ -37,7 +37,7 @@ export function groupBy(arr: readonly T[], getKeyFromI const item = arr[i]; const key = getKeyFromItem(item); - if (!Object.prototype.hasOwnProperty.call(result, key) || result[key] == null) { + if (!Object.hasOwn(result, key) || result[key] == null) { result[key] = []; } From 5ff3039c7b85a47251a26e141908391eb9ef8c07 Mon Sep 17 00:00:00 2001 From: D-Sketon <2055272094@qq.com> Date: Mon, 16 Dec 2024 22:36:23 +0800 Subject: [PATCH 4/4] simpify --- src/array/groupBy.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/array/groupBy.ts b/src/array/groupBy.ts index 09979741a..4ef906d3a 100644 --- a/src/array/groupBy.ts +++ b/src/array/groupBy.ts @@ -37,7 +37,7 @@ export function groupBy(arr: readonly T[], getKeyFromI const item = arr[i]; const key = getKeyFromItem(item); - if (!Object.hasOwn(result, key) || result[key] == null) { + if (!Object.hasOwn(result, key)) { result[key] = []; }