Simply because Math.max() attempts to convert its arguments to numbers. An array does not convert into a number, so you get NaN.

Calling Math.max(...lengths) splits the lengths array into several arguments, which works (so long as they're all numbers, of course).

Answer from AKX on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Math › max
Math.max() - JavaScript | MDN
The Math.max() static method returns the largest of the numbers given as input parameters, or -Infinity if there are no parameters.
🌐
W3Schools
w3schools.com › jsref › jsref_max.asp
W3Schools.com
The Math.max() method returns the number with the highest value.
Discussions

Understanding Math.max()
Math.max doesn't accept an array, just multiple arguments. More on stackoverflow.com
🌐 stackoverflow.com
probability - How can there exist a maximum product for two integers? - Mathematics Stack Exchange
I've come across an interesting question, but the solution has me a little confused and I'd love some insight. Let $M$ be the maximum value of the product of two positive integers when their sum is... More on math.stackexchange.com
🌐 math.stackexchange.com
3 weeks ago
Event Rune math for double max speed rolls
If the drop rates were higher it wouldn’t be so bad I think. More on reddit.com
🌐 r/summonerswar
10
15
July 2, 2020
I did the math no one asked for. To reach max level in Elden Ring, it would take approximately 170 hours at peak perfromance.

This is based on the assumption that a normal person could beat the game, get the end game sword, and golden scarab in about 10 hours. Then with each game it would take about 5 hours to beat. The rune costs are based on Elden Ring wiki multiplier and massacre time based on my brother timing me killing the frog bois. I based runes needed off getting to level 100 by the first playthrough and then subtracting it from the total. After that, I took the runes needed to get to level 100 and multiplied it by the same multiplier and subtracted.

Based on my shitty math, journey 5 is the best place to kill frog bois for maximum efficiency.

More on reddit.com
🌐 r/Eldenring
17
30
October 17, 2020
🌐
Programiz
programiz.com › javascript › library › math › max
JavaScript Math max()
The max() method finds the maximum value among the specified values and returns it. let numbers = Math.max(12, 4, 5, 9, 0, -3); console.log(numbers); // Output: 12
🌐
TradingView
tradingview.com › script › j3mz6K8i-zhumabayevv-sessions
Zhumabayevv_Sessions — Indicator by zhumabayev147
1 week ago - ou are looking back from Monday ... math.min(asiaLow[1], low) else asiaLow[1] float asiaHigh = na asiaHigh := if asiaSession if asiaNewbar high else math.max(asiaHigh[1], high) else asiaHigh[1] int asiaStart = na asiaStart := if asiaSession if asiaNewbar time else ...
🌐
Substack
annamills.substack.com › p › automating-linkedin-search-by-getting
Automating LinkedIn search by getting Claude to build and test a new skill
2 weeks ago - async function scrollAndSearch(keyword, maxScrolls = 30) { for (let i = 0; i < maxScrolls; i++) { window.scrollTo(0, document.body.scrollHeight); await new Promise(r => setTimeout(r, 1500)); if (document.body.innerText.toLowerCase().includes(keyword.toLowerCase())) { const text = document.body.innerText; const idx = text.toLowerCase().indexOf(keyword.toLowerCase()); const start = Math.max(0, idx - 300); const end = Math.min(text.length, idx + 300); return { found: true, scrolls: i + 1, context: text.substring(start, end) }; } } return { found: false, scrolls: maxScrolls }; } scrollAndSearch('your keyword here')
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-math-max-method
Java Math max() Method - GeeksforGeeks
May 14, 2025 - The max() method in Java is a part of java.lang.Math class. This is an inbuilt function in Java that returns maximum of two numbers.
🌐
Wikipedia
en.wikipedia.org › wiki › Maximum_and_minimum
Maximum and minimum - Wikipedia
2 days ago - In mathematical analysis, the maximum and minimum of a function are, respectively, the greatest and least value taken by the function. Known generically as extrema, they may be defined either within a given range (the local or relative extrema) ...
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › Math.html
Math (Java Platform SE 8 )
October 20, 2025 - If the argument is positive infinity or any value greater than or equal to the value of Integer.MAX_VALUE, the result is equal to the value of Integer.MAX_VALUE.
🌐
SamanthaMing
samanthaming.com › basics › math-max
Math.max() | SamanthaMing.com
const array = [1, 20, 5]; const max = Math.max(...array); max; // 20
🌐
Hugo
gohugo.io › functions › math › max
math.Max
April 10, 2025 - Returns the greater of all numbers. Accepts scalars, slices, or both.
🌐
DEV Community
dev.to › yurukusa › the-token-per-dollar-math-running-claude-max-for-30-days-2k1o
The Token-Per-Dollar Math: Running Claude Max for 30 Days - DEV Community
2 weeks ago - Running Claude Max at $200/month is not cheap. It's not profitable yet. The ROI math is brutal at -97.5%.
🌐
Maxmath
maxmath.fun
MaxMath – Maximise your mathematics
MaxMath is a comprehensive and practical mathematical program designed to tackle low numeracy skills among school students.
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › java.lang.math.max
Math.Max Method (Java.Lang) | Microsoft Learn
[<Android.Runtime.Register("max", "(JJ)J", "")>] static member Max : int64 * int64 -> int64 ... Java documentation for java.lang.Math.max(long, long).
🌐
Macmillan Education
macmillaneducation.es › home › international curriculum › maths › max-maths
Max-Maths - Macmillan - Macmillan
July 9, 2020 - MAX MATHS · Home / International Curriculum / Maths / Max-Maths · MAX MATHS · GO TO E-SHOP · It has been designed for International and English-medium schools and includes the following features to ensure a firm understanding and continued progression: Course for over 6 levels ·
Top answer
1 of 2
6

The product of two numbers equals the difference of the squares of their average and the distance.

"I beg your pardon???"

Well, you know that $(a-b) \cdot (a+b) = a^2-b^2$.
Image you want to take the product of two numbers (let's say $37$ and $43$), you do that by calculating the average (which is $40$ in this case) and by calculating the distance to that average (which is $3$ in this case, the distance from $37$ to the average of from $43$ to the average).
Hence, $37 \cdot 43 = (40 - 3) \cdot (40 + 3) = 1600 - 9 = 1591$.

You can say "Ok, that's a neat trick for calculating by heart, but how does it help here?".
Well, you talk about different pairs of numbers, having $66$ as their pairwise sum. That means that their pairwise average ($\frac{\text{sum}}{2}$) is also always equal, being $33$, so you can write both numbers as $33-x$ and $33+x$, and their product equals $33^2-x^2 = 1089 - x^2$.
From that, you can easily see how the product of those two numbers is defined directly by the distance ($x$) to the average (being half of the sum ($66$) this question started with).

2 of 2
3

Now, I'm lost at the word 'maximum'; how can two fixed numbers—and with a fixed sum 66—have a varying product?

These aren't really "fixed numbers," though.

The problem statement tells us that we have "two positive integers." Let's name them $x$ and $y$. We think of both of these integers as being variable—which is to say, we're allowed to vary them. There's a constraint that we have to follow (the sum must be 66), but we can vary them however we want as long as we obey that constraint.

When we vary the numbers $x$ and $y$, their product $xy$ may change as well. The problem statement asks us to find the largest value of $xy$ that we can achieve this way.

Additionally, the solution presents this wonderful statement: [...]

The solution that you were given starts with two premises. One is $x + y = 66$, the constraint that we were given in the problem statement. The other is the equation $\frac{x + y}{2} \ge \sqrt{xy}$, which is the AM–GM inequality. From these premises, it concludes that $xy \le 1089$, which is to say, it's impossible to achieve a product larger than $1089$.

At this point, the solution skips over a step. It should demonstrate that it is possible to obtain $1089$ as a product, but that step has been omitted.

Since we can obtain a product equal to $1089$, but we can't obtain a product larger than $1089$, the largest product we can obtain ($M$) is exactly $1089$.

🌐
Universe Today
universetoday.com › articles › is-the-universe-made-of-math-part-2-the-minimalist-universe
Is the Universe Made of Math? Part 2: The Minimalist Universe - Universe Today
January 11, 2026 - The latest version of this idea comes to us from cosmologist Max Tegmark. I wouldn’t exactly call him a friend of mine – we don’t hang out often enough – but definitely somewhere on the colleague/acquaintance spectrum.
🌐
HealthPlusLife
healthpluslife.com › home › blog › deductible vs. out-of-pocket max: the cost math that matters
Deductible vs. Out-of-Pocket Max: The Cost Math That Matters
January 5, 2026 - If your plan has a $2,000 deductible and a $7,500 out-of-pocket maximum, you pay the first $2,000 of covered care. After that, the plan splits costs through copays or coinsurance until your total spending reaches $7,500.