🌐 AI搜索 & 代理 主页
Skip to content

Conversation

@sapbotgit
Copy link

@sapbotgit sapbotgit commented Nov 11, 2025

Merging this fixes #5901 by documenting this behavior.

Copy link
Member

@jonchurch jonchurch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation is currently generated based on waht is in the JSDoc of the source. Then copied over to the lodash.com repo and deployed.

You will need to make this change in the source's JSDoc to ensure it persists through the next website deploy.

Consider adding an example as well.

diff --git a/lodash.js b/lodash.js
index 1d232ac5e..26fc1939f 100644
--- a/lodash.js
+++ b/lodash.js
@@ -16437,7 +16437,7 @@
      * @category Math
      * @param {Array} array The array to iterate over.
      * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
-     * @returns {number} Returns the mean.
+     * @returns {number} Returns the mean. If array is empty, then will return `NaN`
      * @example
      *
      * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
@@ -16448,6 +16448,10 @@
      * // The `_.property` iteratee shorthand.
      * _.meanBy(objects, 'n');
      * // => 5
+     *
+     * // If array is empty, then will return NaN
+     * _.meanBy([], 'foo')
+     *  // => NaN
      */
     function meanBy(array, iteratee) {
       return baseMean(array, getIteratee(iteratee, 2));

Copy link
Author

@sapbotgit sapbotgit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add @jonchurch changes

@sapbotgit sapbotgit requested a review from jonchurch December 11, 2025 12:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

meanBy returning NaN on empty lists is error prone

4 participants