Skip to content
The Chat Archive
claude-opus-4-20250514· Anthropic LMArena Human Preference 140K

(()=>{ function calculatePrice(brand, productName) { const data = [ ['福人', 800], ['千年舟',…

  1. User

    (()=>{ function calculatePrice(brand, productName) { const data = [ ['福人', 800], ['千年舟', 650], ['兔宝宝', 650], ['莫干山', 650], ['森鹿', 650], ['高度超限', 50], ['深度超限', 100] ]; const entry = data.find(([dataBrand]) => dataBrand.includes(brand)); const basePrice = entry ? entry[1] : 600; return productName.includes("双开") ? basePrice * 1.8 : basePrice; } return calculatePrice([商品品牌],[商品名称]); })(); 为我修改,其中对判断超限的逻辑有问题 因为改数组是用来判断品牌的 ,这个地方应该加一个对名称的判断 我希望你用流式编程 我给你一个案例 你模仿的写 (() => { function calculatePrice(productName, material) { function getWidth(...dimensions) { let sorted = dimensions.slice().sort((a, b) => a - b); return sorted[1]; } const data = [ ['单垭口', '多层', 55], ['单垭口', '欧松', 55], ['单垭口', '颗粒', 45], ['双垭口', '多层', 75], ['双垭口', '欧松', 75], ['双垭口', '颗粒', 65] ]; if (productName.includes("超限")) return Math.ceil((getWidth([加工组长],[加工组宽],[加工组厚])-300)/10)*5; return data .filter(([brand, mat]) => productName.includes(brand) && material.includes(mat)) .map(([, , price]) => price) .concat([0]) // 默认值作为备选 .slice(0, 1)[0]; // 取第一个匹配结果或默认值 } return calculatePrice([商品名称],[商品基材]); })();

  2. Assistant

    我来帮你修改这段代码,使用流式编程风格来处理品牌定价和超限判断:

    (() => {
      function calculatePrice(brand, productName) {
        const brandData = [
          ['福人', 800],
          ['千年舟', 650],
          ['兔宝宝', 650],
          ['莫干山', 650],
          ['森鹿', 650]
        ];
        
        const surchargeData = [
          ['高度超限', 50],
          ['深度超限', 100]
        ];
        
        // 获取基础价格
        const basePrice = brandData
          .filter(([dataBrand]) => dataBrand.includes(brand))
          .map(([, price]) => price)
          .concat([600]) // 默认价格作为备选
          .slice(0, 1)[0];
        
        // 计算超限附加费
        const surcharge = surchargeData
          .filter(([limitType]) => productName.includes(limitType))
          .map(([, charge]) => charge)
          .reduce((sum, charge) => sum + charge, 0);
        
        // 计算最终价格
        const finalPrice = basePrice + surcharge;
        
        // 双开产品价格调整
        return productName.includes("双开") ? finalPrice * 1.8 : finalPrice;
      }
      
      return calculatePrice([商品品牌], [商品名称]);
    })();
    

    这个修改版本:

    1. 将品牌数据和超限数据分离到不同的数组中
    2. 使用 filter 和 map 的流式编程方式获取基础价格
    3. 单独计算超限附加费,支持同时包含多种超限情况
    4. 最后将基础价格和超限费用相加,再根据是否双开进行调整

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