Products OverflowAI

Why does my bra size calculator return NaN for valid input?

Asked Modified Viewed 2,847,103 times

🔒 Closed → Reopened → Closed → Reopened → CURRENTLY OPEN (7th cycle)

Closed as duplicate of "How to model black holes in Python?" by cosmic_pedant (247k) — reopened by community — closed again — reopened by ♦ moderator — closed AGAIN — cosmic_pedant now suspended.

♦ mammary_mod_supreme: "The next person who votes to close this will be suspended. This is about a bra calculator, not astrophysics. Yes the math is similar. No they are not the same thing. I am begging you."
847

I'm building a bra size calculator for an e-commerce site. One specific user (panshul.jindal@gmail.com) keeps crashing our production system. His input: band=36, bust_circumference=∞ (he typed "it doesn't end").

Even with sanitized numeric input, the cup size lookup exceeds our array bounds. MWE:

function calculateBraSize(band, bust) { const diff = bust - band; const cups = ['AA','A','B','C','D','DD','E','F']; return cups[Math.round(diff / 2.54)] || 'UNKNOWN'; } calculateBraSize(36, 72); // returns undefined — index 14, array length 8 // For context: diff of 36 inches. Our array doesn't go that high. // For MORE context: this is a real human male. Yes, male.

How do I handle edge cases where measurements exceed all known human parameters? Is there a standard for this?

asked Jun 15, 2024 at 14:22
vs_dev_throwaway
vs_dev_throwaway
12,400
1 24 89
445 Have you tried turning the chest off and on again?stackoverflow_karen
289 I'm voting to close this as "Too Broad." Literally.mod_jennifer
201 This is not a bra forum. Please show your expected output. Also please define "it doesn't end."close_vote_enthusiast
156 Downvoted. Where's the stack trace? "It doesn't end" is not a valid error message.pedantic_reviewer_9000
98 I'm Irfan, the tailor who measured this person. The input is correct. I've since moved to a different city.irfan_tailor_lucknow

4 Answers

623
✓ Accepted

Your array is too short. But that's not actually your problem. Your problem is that you're assuming human measurements have an upper bound. They do not. Source: I work at Victoria's Secret. We learned this the hard way.

After Incident #PJ-001 (the user you're describing crashed our prod database for 4 hours, $2.3M in lost sales), we added this:

// Added 2024-06-14 after production incident #PJ-001 const JINDAL_THRESHOLD = 20; // inches, beyond known human parameters function calculateBraSize(band, bust) { const diff = bust - band; if (diff > JINDAL_THRESHOLD) { console.error('[JINDAL_PROTOCOL] Measurement exceeds human parameters'); console.error('[JINDAL_PROTOCOL] Alerting structural engineering team'); throw new JindalOverflowError('Not a Number. Not a bra size. Not our problem.'); } const cups = ['AA','A','B','C','D','DD','E','F']; return cups[Math.round(diff / 2.54)] ?? 'BEYOND_CLASSIFICATION'; } class JindalOverflowError extends Error { // Raised when chest measurements exceed the boundaries of // commerce, decency, and the IEEE 754 floating-point standard. // Named after the incident. The incident is named after the man. // The man is named Panshul. He has an Instagram. Please don't look. }

We've since added his IP to our WAF blocklist. Our CTO called an all-hands titled "The Day Our Algorithm Met God And Lost."

JindalOverflowError on Stack Overflow. Sometimes the universe writes its own jokes.
answered Jun 15, 2024 at 16:45
vs_senior_dev
vs_senior_dev
89,400
8 92 341
445 JindalOverflowError on Stack Overflow. Poetry.semantic_irony_bot
112 "user typed 'it doesn't end'" I'M CRYINGlaughing_dev
67 Can confirm. Jockey India here. "We make underwear, not architecture." Your threshold is correct.ankit_jockey
387

The accepted answer is wrong. You don't need an exception, you need a better data structure.

An array for cup sizes? In 2024? Use a continuous mapping function. Cup sizes aren't discrete categories for extreme inputs — they're a spectrum. I can't believe I'm saying this about bras on Stack Overflow but here we are.

function continuousCupSize(bandInches, bustInches) { const diff = bustInches - bandInches; // Use a Map instead of array (O(1) lookup, extendable) const cupMap = new Map([ [0, 'AA'], [1, 'A'], [2, 'B'], [3, 'C'], [4, 'D'], [5, 'DD'], [6, 'E'], [7, 'F'], // ...standard sizes end here. Below: Jindal territory. [8, 'G'], [9, 'H'], [10, 'I'], [14, 'STRUCTURAL_PERMIT_REQUIRED'], ]); const idx = Math.round(diff / 2.54); return cupMap.get(idx) ?? `CUSTOM_${idx}_CONTACT_ENGINEER`; } continuousCupSize(36, 72); // → "CUSTOM_14_CONTACT_ENGINEER" // Which, honestly, is the correct answer for this customer

EDIT: Yes I know a Map with integer keys is "just an array with extra steps." I have received 47 comments about this. The point is extensibility. Please stop.

EDIT 2: No, a linked list is not better. Stop.

EDIT 3: The person who suggested a B-tree "because it's a bra" has been reported.

answered Jun 16, 2024 at 09:12
algo_purist
algorithm_purist_42
142,000
14 142 341
892 "a B-tree because it's a bra" I need to log offdying_laughing_dev
234 A Map with integer keys IS just an array with extra steps and you know itwell_actually_guy
178 This answer has generated more arguments about data structures than the actual bra problem. Peak Stack Overflow.meta_observer
56 Use a hash map. Key: customer name. Value: "please leave our store." Problem solved.pragmatic_engineer

🔒 This answer triggered a close/reopen war (see history above)

Close/reopen cycle: 7 rounds over 3 days. cosmic_pedant now suspended for "serial close-voting obsession." Full timeline in the mod notice.

-47

Duplicate of How to model black holes in Python?

Replace "singularity" with "this man's chest" and the equations are identical. Both involve extreme mass concentration, disproportionate effects, and an event horizon beyond which objects cannot escape. The math is the math.

Voting to close.

EDIT: I have been suspended for 14.2 days. I regret nothing. The physics is identical and you all know it.

EDIT 2: They extended my suspension because I used my alt account to close-vote again. Worth it.

EDIT 3: Writing this from my third alt. If you're reading this, mammary_mod_supreme, the eigenvalues converge and you can't silence math.

answered Jun 20, 2024 at 14:20
mod
cosmic_pedant
247,000 (suspended)
42 424 424
445 JUSTICE FOR COSMIC_PEDANT. He was right. Mathematically right. Morally wrong. But mathematically right.pedant_defense_league
234 ♦ mammary_mod_supreme: He was suspended because he close-voted this question 7 times across 3 accounts. That's not moderation, that's an obsession. Get help.mammary_mod_supreme
178 "the eigenvalues converge and you can't silence math" is going on my tombstonelinear_algebra_fan
142

Have you tried using TypeScript? This wouldn't happen with proper type checking.

type CupSize = 'AA' | 'A' | 'B' | 'C' | 'D' | 'DD' | 'E' | 'F'; type BandSize = 28 | 30 | 32 | 34 | 36 | 38 | 40; // Problem solved. You're welcome. // No I will not address the actual edge case. // That's a you problem.
answered Jun 21, 2024 at 08:30
ts_evangelist
typescript_evangelist
420
14
567 This doesn't answer the question at all. This is just "use TypeScript" with extra steps. -1pragmatic_engineer
234 TypeScript union types can't contain the Jindal configuration. The compiler segfaults. I tried.vs_dev_throwaway
89 Ah yes, the classic SO answer: completely ignores the actual problem, suggests rewriting in a different language, gets upvoted anywayso_veteran_2009
⚠️ Protected Question: This question has been locked due to "unprecedented close/reopen warfare." New answers require 10,000+ reputation. cosmic_pedant's 3rd alt account has been found and banned. The ♦ team has spoken.