Skip to content
TheChatArchiveThe Chat Archive
Claudeclaude-sonnet-4-20250514· AnthropicHugging Face LMArena Human Preference 140K

Why don't I see the comparison of the old an new values in this code:…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with gpt-4.1-2025-04-14’s answer.
  1. User

    Why don't I see the comparison of the old an new values in this code: allValues.forEach(prevValues => { const newValues = prevValues.map((val, index) => { const num = parseFloat(val); if (!isNaN(num)) { const pctChange = (Math.random() * 0.2) - 0.1; return Math.round(num * (1 + pctChange)); } return [val, prevValues[index]]; }); console.log(newValues) });

  2. Claude Assistant

    The issue is in this line:

    return [val, prevValues[index]];
    

    This code only executes when isNaN(num) is true (meaning the value isn't a valid number). For numeric values, you're only returning the new calculated value with Math.round(num * (1 + pctChange)), not a comparison.

    If you want to see both old and new values for all items, you should return an array for numeric values too:

    allValues.forEach(prevValues => {
      const newValues = prevValues.map((val, index) => {
        const num = parseFloat(val);
        if (!isNaN(num)) {
          const pctChange = (Math.random() * 0.2) - 0.1;
          const newVal = Math.round(num * (1 + pctChange));
          return [val, newVal]; // Return both old and new
        }
        return [val, val]; // For non-numeric, return original twice
      });
      console.log(newValues);
    });
    

    Or if you want to see the comparison more clearly, you could format it differently:

    allValues.forEach(prevValues => {
      const newValues = prevValues.map((val, index) => {
        const num = parseFloat(val);
        if (!isNaN(num)) {
          const pctChange = (Math.random() * 0.2) - 0.1;
          const newVal = Math.round(num * (1 + pctChange));
          return `${val} → ${newVal}`;
        }
        return val;
      });
      console.log(newValues);
    });
    

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.