From 37b9281c208e78a441c19b204297cdd9666cbbdc Mon Sep 17 00:00:00 2001 From: jodasom Date: Thu, 2 Jan 2025 16:12:12 +0900 Subject: [PATCH 01/28] feat : reduce implement --- src/array/reduce.spec.ts | 46 ++++++++++++++++++++++++++++++++++++++++ src/array/reduce.ts | 37 ++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 src/array/reduce.spec.ts create mode 100644 src/array/reduce.ts diff --git a/src/array/reduce.spec.ts b/src/array/reduce.spec.ts new file mode 100644 index 000000000..a218fdb9c --- /dev/null +++ b/src/array/reduce.spec.ts @@ -0,0 +1,46 @@ +import { describe, expect, it } from 'vitest'; +import { reduce } from './reduce'; + +describe('reduce', () => { + it('removes elements at specified indices and returns the removed elements', () => { + const arr = [10, 20, 30, 40, 50]; + const removed = reduce(arr, [1, 3, 4]); + expect(removed).toEqual([20, 40, 50]); + expect(arr).toEqual([10, 30]); + }); + + it('returns undefined for out-of-bounds indices', () => { + const arr = [10, 20, 30]; + const removed = reduce(arr, [10, -10]); + expect(removed).toEqual([undefined, undefined]); + expect(arr).toEqual([10, 20, 30]); + }); + + it('handles duplicate indices gracefully', () => { + const arr = [10, 20, 30, 40]; + const removed = reduce(arr, [1, 1, 3]); + expect(removed).toEqual([20, 40]); + expect(arr).toEqual([10, 30]); + }); + + it('removes all elements when all indices are specified', () => { + const arr = [10, 20, 30]; + const removed = reduce(arr, [0, 1, 2]); + expect(removed).toEqual([10, 20, 30]); + expect(arr).toEqual([]); + }); + + it('removes elements in descending order of indices', () => { + const arr = [10, 20, 30, 40, 50]; + const removed = reduce(arr, [4, 0, 2]); + expect(removed).toEqual([10, 30, 50]); + expect(arr).toEqual([20, 40]); + }); + + it('returns an empty array when indices array is empty', () => { + const arr = [10, 20, 30]; + const removed = reduce(arr, []); + expect(removed).toEqual([]); + expect(arr).toEqual([10, 20, 30]); + }); +}); diff --git a/src/array/reduce.ts b/src/array/reduce.ts new file mode 100644 index 000000000..5d760d71d --- /dev/null +++ b/src/array/reduce.ts @@ -0,0 +1,37 @@ +/* + * Removes elements from an array at specified indices and returns the removed elements. + * + * This function supports negative indices, which count from the end of the array. + * + * @template T + * @param {T[]} arr - The array from which elements will be removed. + * @param {number[]} indicesToRemove - An array of indices specifying the positions of elements to remove. + * @returns {Array} An array containing the elements that were removed from the original array. + * + * @example + * import { reduce } from './reduce'; + * + * const numbers = [10, 20, 30, 40, 50]; + * const removed = reduce(numbers, [1, 3, 4]); + * console.log(removed); // [20, 40, 50] + * console.log(numbers); // [10, 30] + */ +export function reduce(arr: T[], indicesToRemove: number[]): Array { + const indicesSet = Array.from( + new Set(indicesToRemove.map((index) => (index < 0 ? arr.length + index : index))) + ).sort((a, b) => b - a); + + const removed: Array = []; + + for (let i = 0; i < indicesSet.length; i++) { + const index = indicesSet[i]; + if (index >= 0 && index < arr.length) { + removed.unshift(arr[index]); // Add the removed element to the front + arr.splice(index, 1); // Remove the element from the array + } else { + removed.unshift(undefined); // Handle out-of-bounds indices + } + } + + return removed; +} From 806ffc6d93dd5242058483bcc7cc415292db84ef Mon Sep 17 00:00:00 2001 From: jodasom Date: Thu, 2 Jan 2025 19:17:05 +0900 Subject: [PATCH 02/28] feat : reduce_function --- src/array/reduce.spec.ts | 7 ------- src/array/reduce.ts | 1 - 2 files changed, 8 deletions(-) diff --git a/src/array/reduce.spec.ts b/src/array/reduce.spec.ts index a218fdb9c..4db01ddd9 100644 --- a/src/array/reduce.spec.ts +++ b/src/array/reduce.spec.ts @@ -36,11 +36,4 @@ describe('reduce', () => { expect(removed).toEqual([10, 30, 50]); expect(arr).toEqual([20, 40]); }); - - it('returns an empty array when indices array is empty', () => { - const arr = [10, 20, 30]; - const removed = reduce(arr, []); - expect(removed).toEqual([]); - expect(arr).toEqual([10, 20, 30]); - }); }); diff --git a/src/array/reduce.ts b/src/array/reduce.ts index 5d760d71d..e7fb6372e 100644 --- a/src/array/reduce.ts +++ b/src/array/reduce.ts @@ -32,6 +32,5 @@ export function reduce(arr: T[], indicesToRemove: number[]): Array Date: Thu, 2 Jan 2025 19:21:54 +0900 Subject: [PATCH 03/28] fix : EsLink ERROR --- src/array/reduce.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/array/reduce.ts b/src/array/reduce.ts index e7fb6372e..4d29698d7 100644 --- a/src/array/reduce.ts +++ b/src/array/reduce.ts @@ -18,7 +18,7 @@ */ export function reduce(arr: T[], indicesToRemove: number[]): Array { const indicesSet = Array.from( - new Set(indicesToRemove.map((index) => (index < 0 ? arr.length + index : index))) + new Set(indicesToRemove.map(index => (index < 0 ? arr.length + index : index))) ).sort((a, b) => b - a); const removed: Array = []; From 71a458468359dfb950575ac1669f7ef82433dde6 Mon Sep 17 00:00:00 2001 From: jodasom Date: Thu, 2 Jan 2025 19:28:21 +0900 Subject: [PATCH 04/28] fix : EsLint error --- src/array/reduce.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/array/reduce.ts b/src/array/reduce.ts index 4d29698d7..f159923ec 100644 --- a/src/array/reduce.ts +++ b/src/array/reduce.ts @@ -1,4 +1,4 @@ -/* +/** * Removes elements from an array at specified indices and returns the removed elements. * * This function supports negative indices, which count from the end of the array. @@ -16,6 +16,7 @@ * console.log(removed); // [20, 40, 50] * console.log(numbers); // [10, 30] */ + export function reduce(arr: T[], indicesToRemove: number[]): Array { const indicesSet = Array.from( new Set(indicesToRemove.map(index => (index < 0 ? arr.length + index : index))) From 5b45837ed5cb2187e7f465f6859c795233fa62fc Mon Sep 17 00:00:00 2001 From: jodasom Date: Thu, 2 Jan 2025 19:40:37 +0900 Subject: [PATCH 05/28] fix : EsLint error --- src/array/reduce.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/array/reduce.ts b/src/array/reduce.ts index f159923ec..49e8e4fdc 100644 --- a/src/array/reduce.ts +++ b/src/array/reduce.ts @@ -19,7 +19,9 @@ export function reduce(arr: T[], indicesToRemove: number[]): Array { const indicesSet = Array.from( - new Set(indicesToRemove.map(index => (index < 0 ? arr.length + index : index))) + new Set( + indicesToRemove.map((index) => (index < 0 ? arr.length + index : index)) + ) ).sort((a, b) => b - a); const removed: Array = []; From 886a68354d7339ea8267708a7069defff6937338 Mon Sep 17 00:00:00 2001 From: jodasom Date: Thu, 2 Jan 2025 19:59:49 +0900 Subject: [PATCH 06/28] fix : EsLint error --- src/array/reduce.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/array/reduce.ts b/src/array/reduce.ts index 49e8e4fdc..c3fffe342 100644 --- a/src/array/reduce.ts +++ b/src/array/reduce.ts @@ -16,8 +16,8 @@ * console.log(removed); // [20, 40, 50] * console.log(numbers); // [10, 30] */ - export function reduce(arr: T[], indicesToRemove: number[]): Array { + // Normalize indices and sort in descending order const indicesSet = Array.from( new Set( indicesToRemove.map((index) => (index < 0 ? arr.length + index : index)) @@ -26,14 +26,15 @@ export function reduce(arr: T[], indicesToRemove: number[]): Array = []; - for (let i = 0; i < indicesSet.length; i++) { - const index = indicesSet[i]; + // Remove elements at specified indices + indicesSet.forEach((index) => { if (index >= 0 && index < arr.length) { removed.unshift(arr[index]); // Add the removed element to the front arr.splice(index, 1); // Remove the element from the array } else { removed.unshift(undefined); // Handle out-of-bounds indices } - } + }); + return removed; } From 309667cf7073065198900857bd547f77b3ff5f9b Mon Sep 17 00:00:00 2001 From: jodasom Date: Thu, 2 Jan 2025 20:31:35 +0900 Subject: [PATCH 07/28] fix : EsLint error --- src/array/reduce.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/array/reduce.ts b/src/array/reduce.ts index c3fffe342..f6a9af28e 100644 --- a/src/array/reduce.ts +++ b/src/array/reduce.ts @@ -7,14 +7,6 @@ * @param {T[]} arr - The array from which elements will be removed. * @param {number[]} indicesToRemove - An array of indices specifying the positions of elements to remove. * @returns {Array} An array containing the elements that were removed from the original array. - * - * @example - * import { reduce } from './reduce'; - * - * const numbers = [10, 20, 30, 40, 50]; - * const removed = reduce(numbers, [1, 3, 4]); - * console.log(removed); // [20, 40, 50] - * console.log(numbers); // [10, 30] */ export function reduce(arr: T[], indicesToRemove: number[]): Array { // Normalize indices and sort in descending order From 8e4a239a579a638abc91d9816d2c89f3e6812f4e Mon Sep 17 00:00:00 2001 From: jodasom Date: Thu, 2 Jan 2025 20:33:26 +0900 Subject: [PATCH 08/28] fix : EsLint error --- src/array/reduce.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/array/reduce.ts b/src/array/reduce.ts index f6a9af28e..37033174b 100644 --- a/src/array/reduce.ts +++ b/src/array/reduce.ts @@ -11,15 +11,13 @@ export function reduce(arr: T[], indicesToRemove: number[]): Array { // Normalize indices and sort in descending order const indicesSet = Array.from( - new Set( - indicesToRemove.map((index) => (index < 0 ? arr.length + index : index)) - ) + new Set(indicesToRemove.map(index => (index < 0 ? arr.length + index : index))) ).sort((a, b) => b - a); const removed: Array = []; // Remove elements at specified indices - indicesSet.forEach((index) => { + indicesSet.forEach(index => { if (index >= 0 && index < arr.length) { removed.unshift(arr[index]); // Add the removed element to the front arr.splice(index, 1); // Remove the element from the array From 6813a2e1fb85a9b7152b9423acb37e8161aa484a Mon Sep 17 00:00:00 2001 From: jodasom Date: Thu, 2 Jan 2025 20:40:26 +0900 Subject: [PATCH 09/28] Add reduce module to index file --- src/compat/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/compat/index.ts b/src/compat/index.ts index dd6896cf7..7e6f3dfb4 100644 --- a/src/compat/index.ts +++ b/src/compat/index.ts @@ -60,6 +60,7 @@ export { nth } from './array/nth.ts'; export { orderBy } from './array/orderBy.ts'; export { pull } from './array/pull.ts'; export { pullAll } from './array/pullAll.ts'; +export { reduce } from '../array/reduce.ts'; export { remove } from './array/remove.ts'; export { reverse } from './array/reverse.ts'; export { sample } from './array/sample.ts'; From b03c7055b4d4337a4a4f2f9299f1e2fc1dab6045 Mon Sep 17 00:00:00 2001 From: jodasom Date: Thu, 2 Jan 2025 20:45:29 +0900 Subject: [PATCH 10/28] fix : EsLint error --- src/array/reduce.ts | 11 +++++++++-- src/compat/index.ts | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/array/reduce.ts b/src/array/reduce.ts index 37033174b..dff181828 100644 --- a/src/array/reduce.ts +++ b/src/array/reduce.ts @@ -8,10 +8,17 @@ * @param {number[]} indicesToRemove - An array of indices specifying the positions of elements to remove. * @returns {Array} An array containing the elements that were removed from the original array. */ -export function reduce(arr: T[], indicesToRemove: number[]): Array { +export function reduce( + arr: T[], + indicesToRemove: number[] +): Array { // Normalize indices and sort in descending order const indicesSet = Array.from( - new Set(indicesToRemove.map(index => (index < 0 ? arr.length + index : index))) + new Set( + indicesToRemove.map(index => + index < 0 ? arr.length + index : index + ) + ) ).sort((a, b) => b - a); const removed: Array = []; diff --git a/src/compat/index.ts b/src/compat/index.ts index 7e6f3dfb4..389725ccb 100644 --- a/src/compat/index.ts +++ b/src/compat/index.ts @@ -60,7 +60,7 @@ export { nth } from './array/nth.ts'; export { orderBy } from './array/orderBy.ts'; export { pull } from './array/pull.ts'; export { pullAll } from './array/pullAll.ts'; -export { reduce } from '../array/reduce.ts'; +export { reduce } from '../array/reduce'; export { remove } from './array/remove.ts'; export { reverse } from './array/reverse.ts'; export { sample } from './array/sample.ts'; From 7146596f041391b5a5b180996a51d9559d92306c Mon Sep 17 00:00:00 2001 From: jodasom Date: Thu, 2 Jan 2025 20:52:55 +0900 Subject: [PATCH 11/28] fix : EsLint error --- src/array/index.ts | 1 + src/array/reduce.ts | 13 ++----------- src/compat/index.ts | 1 - 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/src/array/index.ts b/src/array/index.ts index ad11c147f..df09ce0e1 100644 --- a/src/array/index.ts +++ b/src/array/index.ts @@ -31,6 +31,7 @@ export { orderBy } from './orderBy.ts'; export { partition } from './partition.ts'; export { pull } from './pull.ts'; export { pullAt } from './pullAt.ts'; +export { reduce } from './reduce.ts'; export { remove } from './remove.ts'; export { sample } from './sample.ts'; export { sampleSize } from './sampleSize.ts'; diff --git a/src/array/reduce.ts b/src/array/reduce.ts index dff181828..6390fe87a 100644 --- a/src/array/reduce.ts +++ b/src/array/reduce.ts @@ -8,21 +8,12 @@ * @param {number[]} indicesToRemove - An array of indices specifying the positions of elements to remove. * @returns {Array} An array containing the elements that were removed from the original array. */ -export function reduce( - arr: T[], - indicesToRemove: number[] -): Array { +export function reduce(arr: T[], indicesToRemove: number[]): Array { // Normalize indices and sort in descending order const indicesSet = Array.from( - new Set( - indicesToRemove.map(index => - index < 0 ? arr.length + index : index - ) - ) + new Set(indicesToRemove.map(index => (index < 0 ? arr.length + index : index))) ).sort((a, b) => b - a); - const removed: Array = []; - // Remove elements at specified indices indicesSet.forEach(index => { if (index >= 0 && index < arr.length) { diff --git a/src/compat/index.ts b/src/compat/index.ts index 389725ccb..dd6896cf7 100644 --- a/src/compat/index.ts +++ b/src/compat/index.ts @@ -60,7 +60,6 @@ export { nth } from './array/nth.ts'; export { orderBy } from './array/orderBy.ts'; export { pull } from './array/pull.ts'; export { pullAll } from './array/pullAll.ts'; -export { reduce } from '../array/reduce'; export { remove } from './array/remove.ts'; export { reverse } from './array/reverse.ts'; export { sample } from './array/sample.ts'; From 2f2fd53bb197cff286ea2db1f801a7e4caa5d6de Mon Sep 17 00:00:00 2001 From: jodasom Date: Thu, 2 Jan 2025 20:56:00 +0900 Subject: [PATCH 12/28] fix : EsLint error --- src/array/reduce.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/array/reduce.ts b/src/array/reduce.ts index 6390fe87a..37033174b 100644 --- a/src/array/reduce.ts +++ b/src/array/reduce.ts @@ -13,7 +13,9 @@ export function reduce(arr: T[], indicesToRemove: number[]): Array (index < 0 ? arr.length + index : index))) ).sort((a, b) => b - a); + const removed: Array = []; + // Remove elements at specified indices indicesSet.forEach(index => { if (index >= 0 && index < arr.length) { From c89c1022067c59ab7404f6991b2939c08f417fa3 Mon Sep 17 00:00:00 2001 From: jodasom Date: Thu, 2 Jan 2025 21:01:03 +0900 Subject: [PATCH 13/28] fix : EsLint error --- src/array/reduce.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/array/reduce.ts b/src/array/reduce.ts index 37033174b..8d932eb53 100644 --- a/src/array/reduce.ts +++ b/src/array/reduce.ts @@ -11,20 +11,22 @@ export function reduce(arr: T[], indicesToRemove: number[]): Array { // Normalize indices and sort in descending order const indicesSet = Array.from( - new Set(indicesToRemove.map(index => (index < 0 ? arr.length + index : index))) + new Set( + indicesToRemove.map((index) => (index < 0 ? arr.length + index : index)) + ) ).sort((a, b) => b - a); const removed: Array = []; // Remove elements at specified indices - indicesSet.forEach(index => { + for (const index of indicesSet) { if (index >= 0 && index < arr.length) { removed.unshift(arr[index]); // Add the removed element to the front arr.splice(index, 1); // Remove the element from the array } else { removed.unshift(undefined); // Handle out-of-bounds indices } - }); + } return removed; } From c1946482a488a2707b06289e83d7d8561fde29b5 Mon Sep 17 00:00:00 2001 From: jodasom Date: Thu, 2 Jan 2025 21:03:06 +0900 Subject: [PATCH 14/28] fix : EsLInt error --- src/array/reduce.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/array/reduce.ts b/src/array/reduce.ts index 8d932eb53..7f8dd5464 100644 --- a/src/array/reduce.ts +++ b/src/array/reduce.ts @@ -11,15 +11,14 @@ export function reduce(arr: T[], indicesToRemove: number[]): Array { // Normalize indices and sort in descending order const indicesSet = Array.from( - new Set( - indicesToRemove.map((index) => (index < 0 ? arr.length + index : index)) - ) + new Set(indicesToRemove.map((index) => (index < 0 ? arr.length + index : index))) ).sort((a, b) => b - a); const removed: Array = []; // Remove elements at specified indices - for (const index of indicesSet) { + for (let i = 0; i < indicesSet.length; i++) { + const index = indicesSet[i]; if (index >= 0 && index < arr.length) { removed.unshift(arr[index]); // Add the removed element to the front arr.splice(index, 1); // Remove the element from the array From b6e532f7b0d2f666d8269fd556512126dba5bd6c Mon Sep 17 00:00:00 2001 From: jodasom Date: Tue, 7 Jan 2025 14:46:33 +0900 Subject: [PATCH 15/28] fix : EsLint error --- src/array/reduce.ts | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/array/reduce.ts b/src/array/reduce.ts index 7f8dd5464..9e6131023 100644 --- a/src/array/reduce.ts +++ b/src/array/reduce.ts @@ -3,27 +3,30 @@ * * This function supports negative indices, which count from the end of the array. * - * @template T + * @template T - The type of elements in the array. * @param {T[]} arr - The array from which elements will be removed. * @param {number[]} indicesToRemove - An array of indices specifying the positions of elements to remove. * @returns {Array} An array containing the elements that were removed from the original array. + * + * @example + * const array = [1, 2, 3, 4, 5]; + * const removed = reduce(array, [0, -1]); + * // removed will be [1, 5] + * // array will be [2, 3, 4] */ export function reduce(arr: T[], indicesToRemove: number[]): Array { - // Normalize indices and sort in descending order - const indicesSet = Array.from( + const normalizedIndices = Array.from( new Set(indicesToRemove.map((index) => (index < 0 ? arr.length + index : index))) ).sort((a, b) => b - a); const removed: Array = []; - // Remove elements at specified indices - for (let i = 0; i < indicesSet.length; i++) { - const index = indicesSet[i]; + for (const index of normalizedIndices) { if (index >= 0 && index < arr.length) { - removed.unshift(arr[index]); // Add the removed element to the front - arr.splice(index, 1); // Remove the element from the array + removed.unshift(arr[index]); + arr.splice(index, 1); } else { - removed.unshift(undefined); // Handle out-of-bounds indices + removed.unshift(undefined); } } From f894c8302ca061c6c8d902719d725058055b41cd Mon Sep 17 00:00:00 2001 From: jodasom Date: Tue, 7 Jan 2025 14:48:55 +0900 Subject: [PATCH 16/28] fix : EsLint error --- src/array/reduce.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/array/reduce.ts b/src/array/reduce.ts index 9e6131023..cb0c1d2b7 100644 --- a/src/array/reduce.ts +++ b/src/array/reduce.ts @@ -21,7 +21,8 @@ export function reduce(arr: T[], indicesToRemove: number[]): Array = []; - for (const index of normalizedIndices) { + for (let i = 0; i < normalizedIndices.length; i++) { + const index = normalizedIndices[i]; if (index >= 0 && index < arr.length) { removed.unshift(arr[index]); arr.splice(index, 1); From 8e606742ed113568633339f14d4547728788d7d5 Mon Sep 17 00:00:00 2001 From: jodasom Date: Tue, 7 Jan 2025 14:50:54 +0900 Subject: [PATCH 17/28] fix : EsLInt error --- src/array/reduce.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/array/reduce.ts b/src/array/reduce.ts index cb0c1d2b7..8cbc13dc8 100644 --- a/src/array/reduce.ts +++ b/src/array/reduce.ts @@ -16,7 +16,7 @@ */ export function reduce(arr: T[], indicesToRemove: number[]): Array { const normalizedIndices = Array.from( - new Set(indicesToRemove.map((index) => (index < 0 ? arr.length + index : index))) + new Set(indicesToRemove.map(index => (index < 0 ? arr.length + index : index))) ).sort((a, b) => b - a); const removed: Array = []; From 9d25bf3a76f0e3f6aed060ae95c46b47827dfecc Mon Sep 17 00:00:00 2001 From: jodasom Date: Thu, 30 Jan 2025 19:44:18 +0900 Subject: [PATCH 18/28] Fix: Fixed incorrect reduce function --- src/array/reduce.spec.ts | 71 ++++++++++++++++++++++++---------------- src/array/reduce.ts | 44 ++++++++++--------------- 2 files changed, 61 insertions(+), 54 deletions(-) diff --git a/src/array/reduce.spec.ts b/src/array/reduce.spec.ts index 4db01ddd9..8ee25e3be 100644 --- a/src/array/reduce.spec.ts +++ b/src/array/reduce.spec.ts @@ -1,39 +1,54 @@ -import { describe, expect, it } from 'vitest'; -import { reduce } from './reduce'; +import { describe, expect, it } from "vitest"; +import { reduce } from "./reduce"; -describe('reduce', () => { - it('removes elements at specified indices and returns the removed elements', () => { - const arr = [10, 20, 30, 40, 50]; - const removed = reduce(arr, [1, 3, 4]); - expect(removed).toEqual([20, 40, 50]); - expect(arr).toEqual([10, 30]); +describe("reduce", () => { + it("sums an array of numbers", () => { + const result = reduce([1, 2, 3, 4, 5], (acc, cur) => acc + cur, 0); + expect(result).toBe(15); }); - it('returns undefined for out-of-bounds indices', () => { - const arr = [10, 20, 30]; - const removed = reduce(arr, [10, -10]); - expect(removed).toEqual([undefined, undefined]); - expect(arr).toEqual([10, 20, 30]); + it("multiplies an array of numbers", () => { + const result = reduce([1, 2, 3, 4], (acc, cur) => acc * cur, 1); + expect(result).toBe(24); }); - it('handles duplicate indices gracefully', () => { - const arr = [10, 20, 30, 40]; - const removed = reduce(arr, [1, 1, 3]); - expect(removed).toEqual([20, 40]); - expect(arr).toEqual([10, 30]); + it("concatenates an array of strings", () => { + const result = reduce(["H", "e", "l", "l", "o"], (acc, cur) => acc + cur, ""); + expect(result).toBe("Hello"); }); - it('removes all elements when all indices are specified', () => { - const arr = [10, 20, 30]; - const removed = reduce(arr, [0, 1, 2]); - expect(removed).toEqual([10, 20, 30]); - expect(arr).toEqual([]); + it("works with an empty array and returns the initial value", () => { + const result = reduce([], (acc, cur) => acc + cur, 10); + expect(result).toBe(10); }); - it('removes elements in descending order of indices', () => { - const arr = [10, 20, 30, 40, 50]; - const removed = reduce(arr, [4, 0, 2]); - expect(removed).toEqual([10, 30, 50]); - expect(arr).toEqual([20, 40]); + it("creates an object counting occurrences of elements", () => { + const input = ["a", "b", "a", "c", "b", "a"]; + const result = reduce( + input, + (acc, cur) => { + acc[cur] = (acc[cur] || 0) + 1; + return acc; + }, + {} as Record + ); + + expect(result).toEqual({ a: 3, b: 2, c: 1 }); + }); + + it("reduces an array to find the maximum value", () => { + const result = reduce([5, 1, 8, 3, 10], (acc, cur) => (cur > acc ? cur : acc), -Infinity); + expect(result).toBe(10); + }); + + it("reduces an array to find the minimum value", () => { + const result = reduce([5, 1, 8, 3, 10], (acc, cur) => (cur < acc ? cur : acc), Infinity); + expect(result).toBe(1); + }); + + it("flattens a nested array", () => { + const input = [[1, 2], [3, 4], [5]]; + const result = reduce(input, (acc, cur) => acc.concat(cur), [] as number[]); + expect(result).toEqual([1, 2, 3, 4, 5]); }); }); diff --git a/src/array/reduce.ts b/src/array/reduce.ts index 8cbc13dc8..32e2426f1 100644 --- a/src/array/reduce.ts +++ b/src/array/reduce.ts @@ -1,35 +1,27 @@ /** - * Removes elements from an array at specified indices and returns the removed elements. + * Custom implementation of the Array.prototype.reduce function. * - * This function supports negative indices, which count from the end of the array. - * - * @template T - The type of elements in the array. - * @param {T[]} arr - The array from which elements will be removed. - * @param {number[]} indicesToRemove - An array of indices specifying the positions of elements to remove. - * @returns {Array} An array containing the elements that were removed from the original array. + * @template T, U + * @param {T[]} array - The array to iterate over. + * @param {(accumulator: U, currentValue: T, currentIndex: number, array: T[]) => U} callback + * - The function to execute on each element in the array. + * @param {U} initialValue - The initial value of the accumulator. + * @returns {U} The final accumulated value. * * @example - * const array = [1, 2, 3, 4, 5]; - * const removed = reduce(array, [0, -1]); - * // removed will be [1, 5] - * // array will be [2, 3, 4] + * const sum = reduce([1, 2, 3, 4], (acc, cur) => acc + cur, 0); + * console.log(sum); // 10 */ -export function reduce(arr: T[], indicesToRemove: number[]): Array { - const normalizedIndices = Array.from( - new Set(indicesToRemove.map(index => (index < 0 ? arr.length + index : index))) - ).sort((a, b) => b - a); - - const removed: Array = []; +export function reduce( + array: T[], + callback: (accumulator: U, currentValue: T, currentIndex: number, array: T[]) => U, + initialValue: U +): U { + let accumulator = initialValue; - for (let i = 0; i < normalizedIndices.length; i++) { - const index = normalizedIndices[i]; - if (index >= 0 && index < arr.length) { - removed.unshift(arr[index]); - arr.splice(index, 1); - } else { - removed.unshift(undefined); - } + for (let i = 0; i < array.length; i++) { + accumulator = callback(accumulator, array[i], i, array); } - return removed; + return accumulator; } From 8d7c740b53e71b39c68315dcc1d1a098d684b895 Mon Sep 17 00:00:00 2001 From: jodasom Date: Thu, 30 Jan 2025 19:48:58 +0900 Subject: [PATCH 19/28] fix : eslint --- src/array/reduce.spec.ts | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/array/reduce.spec.ts b/src/array/reduce.spec.ts index 8ee25e3be..1bd8e3dc3 100644 --- a/src/array/reduce.spec.ts +++ b/src/array/reduce.spec.ts @@ -1,29 +1,29 @@ -import { describe, expect, it } from "vitest"; -import { reduce } from "./reduce"; +import { describe, expect, it } from 'vitest'; +import { reduce } from './reduce'; -describe("reduce", () => { - it("sums an array of numbers", () => { +describe('reduce', () => { + it('sums an array of numbers', () => { const result = reduce([1, 2, 3, 4, 5], (acc, cur) => acc + cur, 0); expect(result).toBe(15); }); - it("multiplies an array of numbers", () => { + it('multiplies an array of numbers', () => { const result = reduce([1, 2, 3, 4], (acc, cur) => acc * cur, 1); expect(result).toBe(24); }); - it("concatenates an array of strings", () => { - const result = reduce(["H", "e", "l", "l", "o"], (acc, cur) => acc + cur, ""); - expect(result).toBe("Hello"); + it('concatenates an array of strings', () => { + const result = reduce(['H', 'e', 'l', 'l', 'o'], (acc, cur) => acc + cur, ''); + expect(result).toBe('Hello'); }); - it("works with an empty array and returns the initial value", () => { + it('works with an empty array and returns the initial value', () => { const result = reduce([], (acc, cur) => acc + cur, 10); expect(result).toBe(10); }); - it("creates an object counting occurrences of elements", () => { - const input = ["a", "b", "a", "c", "b", "a"]; + it('creates an object counting occurrences of elements', () => { + const input = ['a', 'b', 'a', 'c', 'b', 'a']; const result = reduce( input, (acc, cur) => { @@ -36,17 +36,17 @@ describe("reduce", () => { expect(result).toEqual({ a: 3, b: 2, c: 1 }); }); - it("reduces an array to find the maximum value", () => { + it('reduces an array to find the maximum value', () => { const result = reduce([5, 1, 8, 3, 10], (acc, cur) => (cur > acc ? cur : acc), -Infinity); expect(result).toBe(10); }); - it("reduces an array to find the minimum value", () => { + it('reduces an array to find the minimum value', () => { const result = reduce([5, 1, 8, 3, 10], (acc, cur) => (cur < acc ? cur : acc), Infinity); expect(result).toBe(1); }); - it("flattens a nested array", () => { + it('flattens a nested array', () => { const input = [[1, 2], [3, 4], [5]]; const result = reduce(input, (acc, cur) => acc.concat(cur), [] as number[]); expect(result).toEqual([1, 2, 3, 4, 5]); From 35f3698a7c762741edf11a10d21cd234a747c761 Mon Sep 17 00:00:00 2001 From: jodasom Date: Thu, 30 Jan 2025 19:56:41 +0900 Subject: [PATCH 20/28] fix:eslint --- src/array/reduce.spec.ts | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/src/array/reduce.spec.ts b/src/array/reduce.spec.ts index 1bd8e3dc3..a36722f5a 100644 --- a/src/array/reduce.spec.ts +++ b/src/array/reduce.spec.ts @@ -3,22 +3,34 @@ import { reduce } from './reduce'; describe('reduce', () => { it('sums an array of numbers', () => { - const result = reduce([1, 2, 3, 4, 5], (acc, cur) => acc + cur, 0); + const result = reduce( + [1, 2, 3, 4, 5], + (acc, cur) => acc + cur, + 0 + ); expect(result).toBe(15); }); it('multiplies an array of numbers', () => { - const result = reduce([1, 2, 3, 4], (acc, cur) => acc * cur, 1); + const result = reduce( + [1, 2, 3, 4], + (acc, cur) => acc * cur, + 1 + ); expect(result).toBe(24); }); it('concatenates an array of strings', () => { - const result = reduce(['H', 'e', 'l', 'l', 'o'], (acc, cur) => acc + cur, ''); + const result = reduce( + ['H', 'e', 'l', 'l', 'o'], + (acc, cur) => acc + cur, + '' + ); expect(result).toBe('Hello'); }); it('works with an empty array and returns the initial value', () => { - const result = reduce([], (acc, cur) => acc + cur, 10); + const result = reduce([], (acc, cur) => acc + cur, 10); expect(result).toBe(10); }); @@ -27,7 +39,7 @@ describe('reduce', () => { const result = reduce( input, (acc, cur) => { - acc[cur] = (acc[cur] || 0) + 1; + acc[cur] = (acc[cur] ?? 0) + 1; return acc; }, {} as Record @@ -37,18 +49,30 @@ describe('reduce', () => { }); it('reduces an array to find the maximum value', () => { - const result = reduce([5, 1, 8, 3, 10], (acc, cur) => (cur > acc ? cur : acc), -Infinity); + const result = reduce( + [5, 1, 8, 3, 10], + (acc, cur) => (cur > acc ? cur : acc), + -Infinity + ); expect(result).toBe(10); }); it('reduces an array to find the minimum value', () => { - const result = reduce([5, 1, 8, 3, 10], (acc, cur) => (cur < acc ? cur : acc), Infinity); + const result = reduce( + [5, 1, 8, 3, 10], + (acc, cur) => (cur < acc ? cur : acc), + Infinity + ); expect(result).toBe(1); }); it('flattens a nested array', () => { const input = [[1, 2], [3, 4], [5]]; - const result = reduce(input, (acc, cur) => acc.concat(cur), [] as number[]); + const result = reduce( + input, + (acc, cur) => acc.concat(cur), + [] as number[] + ); expect(result).toEqual([1, 2, 3, 4, 5]); }); }); From 31e363d17218a2753fe8bf51b8fab9d6e474ea12 Mon Sep 17 00:00:00 2001 From: jodasom Date: Thu, 30 Jan 2025 19:59:06 +0900 Subject: [PATCH 21/28] fix : eslint --- src/array/reduce.spec.ts | 49 ++++++++-------------------------------- 1 file changed, 10 insertions(+), 39 deletions(-) diff --git a/src/array/reduce.spec.ts b/src/array/reduce.spec.ts index a36722f5a..0ee26c780 100644 --- a/src/array/reduce.spec.ts +++ b/src/array/reduce.spec.ts @@ -3,29 +3,17 @@ import { reduce } from './reduce'; describe('reduce', () => { it('sums an array of numbers', () => { - const result = reduce( - [1, 2, 3, 4, 5], - (acc, cur) => acc + cur, - 0 - ); + const result = reduce([1, 2, 3, 4, 5], (acc, cur) => acc + cur, 0); expect(result).toBe(15); }); it('multiplies an array of numbers', () => { - const result = reduce( - [1, 2, 3, 4], - (acc, cur) => acc * cur, - 1 - ); + const result = reduce([1, 2, 3, 4], (acc, cur) => acc * cur, 1); expect(result).toBe(24); }); it('concatenates an array of strings', () => { - const result = reduce( - ['H', 'e', 'l', 'l', 'o'], - (acc, cur) => acc + cur, - '' - ); + const result = reduce(['H', 'e', 'l', 'l', 'o'], (acc, cur) => acc + cur, ''); expect(result).toBe('Hello'); }); @@ -36,43 +24,26 @@ describe('reduce', () => { it('creates an object counting occurrences of elements', () => { const input = ['a', 'b', 'a', 'c', 'b', 'a']; - const result = reduce( - input, - (acc, cur) => { - acc[cur] = (acc[cur] ?? 0) + 1; - return acc; - }, - {} as Record - ); - + const result = reduce(input, (acc, cur) => { + acc[cur] = (acc[cur] ?? 0) + 1; + return acc; + }, {} as Record); expect(result).toEqual({ a: 3, b: 2, c: 1 }); }); it('reduces an array to find the maximum value', () => { - const result = reduce( - [5, 1, 8, 3, 10], - (acc, cur) => (cur > acc ? cur : acc), - -Infinity - ); + const result = reduce([5, 1, 8, 3, 10], (acc, cur) => (cur > acc ? cur : acc), -Infinity); expect(result).toBe(10); }); it('reduces an array to find the minimum value', () => { - const result = reduce( - [5, 1, 8, 3, 10], - (acc, cur) => (cur < acc ? cur : acc), - Infinity - ); + const result = reduce([5, 1, 8, 3, 10], (acc, cur) => (cur < acc ? cur : acc), Infinity); expect(result).toBe(1); }); it('flattens a nested array', () => { const input = [[1, 2], [3, 4], [5]]; - const result = reduce( - input, - (acc, cur) => acc.concat(cur), - [] as number[] - ); + const result = reduce(input, (acc, cur) => acc.concat(cur), [] as number[]); expect(result).toEqual([1, 2, 3, 4, 5]); }); }); From 744058a03d5b8e82f91caffadd3b3a750adc159c Mon Sep 17 00:00:00 2001 From: jodasom Date: Thu, 30 Jan 2025 20:01:12 +0900 Subject: [PATCH 22/28] fix: eslint --- src/array/reduce.spec.ts | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/array/reduce.spec.ts b/src/array/reduce.spec.ts index 0ee26c780..2bcfa1c86 100644 --- a/src/array/reduce.spec.ts +++ b/src/array/reduce.spec.ts @@ -22,15 +22,6 @@ describe('reduce', () => { expect(result).toBe(10); }); - it('creates an object counting occurrences of elements', () => { - const input = ['a', 'b', 'a', 'c', 'b', 'a']; - const result = reduce(input, (acc, cur) => { - acc[cur] = (acc[cur] ?? 0) + 1; - return acc; - }, {} as Record); - expect(result).toEqual({ a: 3, b: 2, c: 1 }); - }); - it('reduces an array to find the maximum value', () => { const result = reduce([5, 1, 8, 3, 10], (acc, cur) => (cur > acc ? cur : acc), -Infinity); expect(result).toBe(10); From 9b9726ac458c93a8860a87fb7151968a86b9ba28 Mon Sep 17 00:00:00 2001 From: jodasom Date: Thu, 30 Jan 2025 20:07:42 +0900 Subject: [PATCH 23/28] fix:eslint --- src/array/reduce.spec.ts | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/src/array/reduce.spec.ts b/src/array/reduce.spec.ts index 2bcfa1c86..682f6d5c8 100644 --- a/src/array/reduce.spec.ts +++ b/src/array/reduce.spec.ts @@ -22,19 +22,46 @@ describe('reduce', () => { expect(result).toBe(10); }); + it('creates an object counting occurrences of elements', () => { + const input = ['a', 'b', 'a', 'c', 'b', 'a']; + const result = reduce( + input, + (acc, cur) => { + acc[cur] = (acc[cur] ?? 0) + 1; + return acc; + }, + {} as Record + ); + + expect(result).toEqual({ a: 3, b: 2, c: 1 }); + }); + it('reduces an array to find the maximum value', () => { - const result = reduce([5, 1, 8, 3, 10], (acc, cur) => (cur > acc ? cur : acc), -Infinity); + const result = reduce( + [5, 1, 8, 3, 10], + (acc, cur) => (cur > acc ? cur : acc), + -Infinity + ); expect(result).toBe(10); }); it('reduces an array to find the minimum value', () => { - const result = reduce([5, 1, 8, 3, 10], (acc, cur) => (cur < acc ? cur : acc), Infinity); + const result = reduce( + [5, 1, 8, 3, 10], + (acc, cur) => (cur < acc ? cur : acc), + Infinity + ); expect(result).toBe(1); }); it('flattens a nested array', () => { const input = [[1, 2], [3, 4], [5]]; - const result = reduce(input, (acc, cur) => acc.concat(cur), [] as number[]); + const result = reduce( + input, + (acc, cur) => acc.concat(cur), + [] as number[] + ); + expect(result).toEqual([1, 2, 3, 4, 5]); }); }); From d95c18e7ba4c16e627ae382e2805378bf0e35deb Mon Sep 17 00:00:00 2001 From: jodasom Date: Thu, 30 Jan 2025 20:10:21 +0900 Subject: [PATCH 24/28] fix:eslint --- src/array/reduce.spec.ts | 29 ++++------------------------- 1 file changed, 4 insertions(+), 25 deletions(-) diff --git a/src/array/reduce.spec.ts b/src/array/reduce.spec.ts index 682f6d5c8..eda4f8338 100644 --- a/src/array/reduce.spec.ts +++ b/src/array/reduce.spec.ts @@ -24,44 +24,23 @@ describe('reduce', () => { it('creates an object counting occurrences of elements', () => { const input = ['a', 'b', 'a', 'c', 'b', 'a']; - const result = reduce( - input, - (acc, cur) => { - acc[cur] = (acc[cur] ?? 0) + 1; - return acc; - }, - {} as Record - ); - + const result = reduce(input, (acc, cur) => (acc[cur] = (acc[cur] ?? 0) + 1, acc), {} as Record); expect(result).toEqual({ a: 3, b: 2, c: 1 }); }); it('reduces an array to find the maximum value', () => { - const result = reduce( - [5, 1, 8, 3, 10], - (acc, cur) => (cur > acc ? cur : acc), - -Infinity - ); + const result = reduce([5, 1, 8, 3, 10], (acc, cur) => (cur > acc ? cur : acc), -Infinity); expect(result).toBe(10); }); it('reduces an array to find the minimum value', () => { - const result = reduce( - [5, 1, 8, 3, 10], - (acc, cur) => (cur < acc ? cur : acc), - Infinity - ); + const result = reduce([5, 1, 8, 3, 10], (acc, cur) => (cur < acc ? cur : acc), Infinity); expect(result).toBe(1); }); it('flattens a nested array', () => { const input = [[1, 2], [3, 4], [5]]; - const result = reduce( - input, - (acc, cur) => acc.concat(cur), - [] as number[] - ); - + const result = reduce(input, (acc, cur) => acc.concat(cur), [] as number[]); expect(result).toEqual([1, 2, 3, 4, 5]); }); }); From f12e5195f9c08477d70d18a04ee180bff1ee605c Mon Sep 17 00:00:00 2001 From: jodasom Date: Thu, 30 Jan 2025 20:14:01 +0900 Subject: [PATCH 25/28] fix : eslint --- src/array/reduce.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/array/reduce.spec.ts b/src/array/reduce.spec.ts index eda4f8338..1530be5c5 100644 --- a/src/array/reduce.spec.ts +++ b/src/array/reduce.spec.ts @@ -24,7 +24,7 @@ describe('reduce', () => { it('creates an object counting occurrences of elements', () => { const input = ['a', 'b', 'a', 'c', 'b', 'a']; - const result = reduce(input, (acc, cur) => (acc[cur] = (acc[cur] ?? 0) + 1, acc), {} as Record); + const result = reduce(input, (acc, cur) => ((acc[cur] = (acc[cur] ?? 0) + 1), acc), {} as Record); expect(result).toEqual({ a: 3, b: 2, c: 1 }); }); From fa3db3059690a649be32b594c6af7e66752e8cdc Mon Sep 17 00:00:00 2001 From: jodasom Date: Fri, 31 Jan 2025 12:26:40 +0900 Subject: [PATCH 26/28] fix : eslint --- src/array/reduce.spec.ts | 49 +++++++--------------------------------- 1 file changed, 8 insertions(+), 41 deletions(-) diff --git a/src/array/reduce.spec.ts b/src/array/reduce.spec.ts index 1530be5c5..c33f7fee4 100644 --- a/src/array/reduce.spec.ts +++ b/src/array/reduce.spec.ts @@ -2,45 +2,12 @@ import { describe, expect, it } from 'vitest'; import { reduce } from './reduce'; describe('reduce', () => { - it('sums an array of numbers', () => { - const result = reduce([1, 2, 3, 4, 5], (acc, cur) => acc + cur, 0); - expect(result).toBe(15); - }); - - it('multiplies an array of numbers', () => { - const result = reduce([1, 2, 3, 4], (acc, cur) => acc * cur, 1); - expect(result).toBe(24); - }); - - it('concatenates an array of strings', () => { - const result = reduce(['H', 'e', 'l', 'l', 'o'], (acc, cur) => acc + cur, ''); - expect(result).toBe('Hello'); - }); - - it('works with an empty array and returns the initial value', () => { - const result = reduce([], (acc, cur) => acc + cur, 10); - expect(result).toBe(10); - }); - - it('creates an object counting occurrences of elements', () => { - const input = ['a', 'b', 'a', 'c', 'b', 'a']; - const result = reduce(input, (acc, cur) => ((acc[cur] = (acc[cur] ?? 0) + 1), acc), {} as Record); - expect(result).toEqual({ a: 3, b: 2, c: 1 }); - }); - - it('reduces an array to find the maximum value', () => { - const result = reduce([5, 1, 8, 3, 10], (acc, cur) => (cur > acc ? cur : acc), -Infinity); - expect(result).toBe(10); - }); - - it('reduces an array to find the minimum value', () => { - const result = reduce([5, 1, 8, 3, 10], (acc, cur) => (cur < acc ? cur : acc), Infinity); - expect(result).toBe(1); - }); - - it('flattens a nested array', () => { - const input = [[1, 2], [3, 4], [5]]; - const result = reduce(input, (acc, cur) => acc.concat(cur), [] as number[]); - expect(result).toEqual([1, 2, 3, 4, 5]); - }); + it('sums an array of numbers', () => expect(reduce([1, 2, 3, 4, 5], (acc, cur) => acc + cur, 0)).toBe(15)); + it('multiplies an array of numbers', () => expect(reduce([1, 2, 3, 4], (acc, cur) => acc * cur, 1)).toBe(24)); + it('concatenates an array of strings', () => expect(reduce(['H', 'e', 'l', 'l', 'o'], (acc, cur) => acc + cur, '')).toBe('Hello')); + it('works with an empty array and returns the initial value', () => expect(reduce([], (acc, cur) => acc + cur, 10)).toBe(10)); + it('creates an object counting occurrences of elements', () => expect(reduce(['a', 'b', 'a', 'c', 'b', 'a'], (acc, cur) => ((acc[cur] = (acc[cur] ?? 0) + 1), acc), {} as Record)).toEqual({ a: 3, b: 2, c: 1 })); + it('reduces an array to find the maximum value', () => expect(reduce([5, 1, 8, 3, 10], (acc, cur) => (cur > acc ? cur : acc), -Infinity)).toBe(10)); + it('reduces an array to find the minimum value', () => expect(reduce([5, 1, 8, 3, 10], (acc, cur) => (cur < acc ? cur : acc), Infinity)).toBe(1)); + it('flattens a nested array', () => expect(reduce([[1, 2], [3, 4], [5]], (acc, cur) => acc.concat(cur), [] as number[])).toEqual([1, 2, 3, 4, 5])); }); From 91fc0e8308404a9bf522d19fd3b077b03ef33657 Mon Sep 17 00:00:00 2001 From: Sojin Park Date: Sat, 1 Feb 2025 08:19:31 +0900 Subject: [PATCH 27/28] feat(reduce): Match the behavior of lodash's reduce --- .../components/CompatibilityStatus.vue | 22 +- docs/ja/reference/compat/array/reduce.md | 74 +++++++ docs/ko/reference/compat/array/reduce.md | 74 +++++++ docs/reference/compat/array/reduce.md | 74 +++++++ docs/zh_hans/reference/compat/array/reduce.md | 74 +++++++ src/array/reduce.spec.ts | 13 -- src/array/reduce.ts | 27 --- src/compat/array/reduce.spec.ts | 180 ++++++++++++++++ src/compat/array/reduce.ts | 198 ++++++++++++++++++ src/compat/index.ts | 1 + 10 files changed, 680 insertions(+), 57 deletions(-) create mode 100644 docs/ja/reference/compat/array/reduce.md create mode 100644 docs/ko/reference/compat/array/reduce.md create mode 100644 docs/reference/compat/array/reduce.md create mode 100644 docs/zh_hans/reference/compat/array/reduce.md delete mode 100644 src/array/reduce.spec.ts delete mode 100644 src/array/reduce.ts create mode 100644 src/compat/array/reduce.spec.ts create mode 100644 src/compat/array/reduce.ts diff --git a/docs/.vitepress/components/CompatibilityStatus.vue b/docs/.vitepress/components/CompatibilityStatus.vue index fd275d1c7..8ec16538a 100644 --- a/docs/.vitepress/components/CompatibilityStatus.vue +++ b/docs/.vitepress/components/CompatibilityStatus.vue @@ -40,17 +40,10 @@ const ids = titles.map(title => title.toLowerCase().replaceAll('"', '').replace(