@@ -16450,12 +16450,17 @@
1645016450 /**
1645116451 * Computes the mean of the values in `array`.
1645216452 *
16453+ * **Note:** This method does not coerce values to numbers. If the array
16454+ * contains non-numeric values, unexpected results may occur due to JavaScript's
16455+ * type coercion rules. For predictable results, ensure array contains only numbers.
16456+ * See [#5818](https://github.com/lodash/lodash/issues/5818) for details.
16457+ *
1645316458 * @static
1645416459 * @memberOf _
1645516460 * @since 4.0.0
1645616461 * @category Math
1645716462 * @param {Array} array The array to iterate over.
16458- * @returns {number} Returns the mean.
16463+ * @returns {number|* } Returns the mean.
1645916464 * @example
1646016465 *
1646116466 * _.mean([4, 2, 8, 6]);
@@ -16470,13 +16475,18 @@
1647016475 * invoked for each element in `array` to generate the value to be averaged.
1647116476 * The iteratee is invoked with one argument: (value).
1647216477 *
16478+ * **Note:** The iteratee should return numeric values. If non-numeric values
16479+ * are returned, unexpected results may occur due to JavaScript's type coercion
16480+ * rules. For predictable results, ensure the iteratee returns only numbers.
16481+ * See [#5818](https://github.com/lodash/lodash/issues/5818) for details.
16482+ *
1647316483 * @static
1647416484 * @memberOf _
1647516485 * @since 4.7.0
1647616486 * @category Math
1647716487 * @param {Array} array The array to iterate over.
1647816488 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
16479- * @returns {number} Returns the mean.
16489+ * @returns {number|* } Returns the mean.
1648016490 * @example
1648116491 *
1648216492 * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
@@ -16609,16 +16619,26 @@
1660916619 /**
1661016620 * Computes the sum of the values in `array`.
1661116621 *
16622+ * **Note:** This method does not coerce values to numbers. If the array
16623+ * contains non-numeric values (e.g., strings), JavaScript's `+` operator will
16624+ * perform string concatenation instead of addition, leading to unexpected results.
16625+ * For predictable results, ensure array contains only numbers.
16626+ * See [#5818](https://github.com/lodash/lodash/issues/5818) for details.
16627+ *
1661216628 * @static
1661316629 * @memberOf _
1661416630 * @since 3.4.0
1661516631 * @category Math
1661616632 * @param {Array} array The array to iterate over.
16617- * @returns {number} Returns the sum.
16633+ * @returns {number|string } Returns the sum, or a string if non-numeric values are present .
1661816634 * @example
1661916635 *
1662016636 * _.sum([4, 2, 8, 6]);
1662116637 * // => 20
16638+ *
16639+ * // Non-numeric values result in string concatenation (not recommended)
16640+ * _.sum(['1', '2']);
16641+ * // => '12'
1662216642 */
1662316643 function sum(array) {
1662416644 return (array && array.length)
@@ -16631,13 +16651,19 @@
1663116651 * invoked for each element in `array` to generate the value to be summed.
1663216652 * The iteratee is invoked with one argument: (value).
1663316653 *
16654+ * **Note:** The iteratee should return numeric values. If non-numeric values
16655+ * are returned (e.g., strings), JavaScript's `+` operator will perform string
16656+ * concatenation instead of addition, leading to unexpected results.
16657+ * For predictable results, ensure the iteratee returns only numbers.
16658+ * See [#5818](https://github.com/lodash/lodash/issues/5818) for details.
16659+ *
1663416660 * @static
1663516661 * @memberOf _
1663616662 * @since 4.0.0
1663716663 * @category Math
1663816664 * @param {Array} array The array to iterate over.
1663916665 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
16640- * @returns {number} Returns the sum.
16666+ * @returns {number|string } Returns the sum, or a string if non-numeric values are present .
1664116667 * @example
1664216668 *
1664316669 * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
1664816674 * // The `_.property` iteratee shorthand.
1664916675 * _.sumBy(objects, 'n');
1665016676 * // => 20
16677+ *
16678+ * // Non-numeric values result in string concatenation (not recommended)
16679+ * _.sumBy([{ 'a': '1' }, { 'a': '2' }], 'a');
16680+ * // => '12'
1665116681 */
1665216682 function sumBy(array, iteratee) {
1665316683 return (array && array.length)
0 commit comments