es-toolkit 1.39.10-dev.1599 → 1.39.10-dev.1600

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,14 +5,15 @@
5
5
  * If the array is empty, this function returns `0`.
6
6
  *
7
7
  * @template T - The type of elements in the array.
8
- * @param {T[]} items An array to calculate the sum.
9
- * @param {(element: T) => number} getValue A function that selects a numeric value from each element.
8
+ * @param {readonly T[]} items - An array to calculate the sum.
9
+ * @param {(element: T, index: number) => number} getValue - A function that selects a numeric value from each element.
10
+ * It receives the element and its zero‑based index in the array.
10
11
  * @returns {number} The sum of all the numbers as determined by the `getValue` function.
11
12
  *
12
13
  * @example
13
- * sumBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: 6
14
- * sumBy([], x => x.a); // Returns: 0
14
+ * sumBy([{ a: 1 }, { a: 2 }, { a: 3 }], (x, i) => x.a * i); // Returns: 8
15
+ * sumBy([], () => 1); // Returns: 0
15
16
  */
16
- declare function sumBy<T>(items: readonly T[], getValue: (element: T) => number): number;
17
+ declare function sumBy<T>(items: readonly T[], getValue: (element: T, index: number) => number): number;
17
18
 
18
19
  export { sumBy };
@@ -5,14 +5,15 @@
5
5
  * If the array is empty, this function returns `0`.
6
6
  *
7
7
  * @template T - The type of elements in the array.
8
- * @param {T[]} items An array to calculate the sum.
9
- * @param {(element: T) => number} getValue A function that selects a numeric value from each element.
8
+ * @param {readonly T[]} items - An array to calculate the sum.
9
+ * @param {(element: T, index: number) => number} getValue - A function that selects a numeric value from each element.
10
+ * It receives the element and its zero‑based index in the array.
10
11
  * @returns {number} The sum of all the numbers as determined by the `getValue` function.
11
12
  *
12
13
  * @example
13
- * sumBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: 6
14
- * sumBy([], x => x.a); // Returns: 0
14
+ * sumBy([{ a: 1 }, { a: 2 }, { a: 3 }], (x, i) => x.a * i); // Returns: 8
15
+ * sumBy([], () => 1); // Returns: 0
15
16
  */
16
- declare function sumBy<T>(items: readonly T[], getValue: (element: T) => number): number;
17
+ declare function sumBy<T>(items: readonly T[], getValue: (element: T, index: number) => number): number;
17
18
 
18
19
  export { sumBy };
@@ -5,7 +5,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
5
5
  function sumBy(items, getValue) {
6
6
  let result = 0;
7
7
  for (let i = 0; i < items.length; i++) {
8
- result += getValue(items[i]);
8
+ result += getValue(items[i], i);
9
9
  }
10
10
  return result;
11
11
  }
@@ -1,7 +1,7 @@
1
1
  function sumBy(items, getValue) {
2
2
  let result = 0;
3
3
  for (let i = 0; i < items.length; i++) {
4
- result += getValue(items[i]);
4
+ result += getValue(items[i], i);
5
5
  }
6
6
  return result;
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "es-toolkit",
3
- "version": "1.39.10-dev.1599+6525f2a3",
3
+ "version": "1.39.10-dev.1600+579af7b1",
4
4
  "description": "A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.",
5
5
  "homepage": "https://es-toolkit.dev",
6
6
  "bugs": "https://github.com/toss/es-toolkit/issues",