Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
527 views
in Technique[技术] by (71.8m points)

我想要问一下这段代码是啥的简写形式?感觉像for循环或者if条件,可以帮我写全一下吗

 h + 1 == a &&
          (r % 2 == 0 && (m += "用来执行添加数组判断的"),
          (m +=
            p == h + 1
              ? this.resultData.push({
                  title: `${p}期(高月供)`,
                  value: `${this.priceFormat(s)}`
                })
              : this.resultData.push({
                  title: `${p}~${h + 1}期`,
                  value: `${this.priceFormat(s)}`
                })),
          (m +=
            r % 2 == 1 ? "用来执行添加数组判断的" : "用来执行添加数组判断的"),
          r++);

结合各位大佬和我自己反复试验的结果如下

if (h + 1 === a) {
          if (p === h + 1) {
            this.resultData.push({
              title: `${p}期(高月供)`,
              value: `${s}`
            })
          } else {
            this.resultData.push({
              title: `${p}~${h + 1}期`,
              value: `${s}`
            })
          }
          r = r + 1
        }

这个m += "用来执行添加数组判断的" 根本就没有啥作用 本质就是if判断加上变量赋值


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

我也不确定对不对啊,就是好奇写了一下,你可以验证下试试看

if (h + 1 == a) {
    if (r % 2 == 0)  {
        m += "用来执行添加数组判断的"
        
        if (p == h + 1) {
            this.resultData.push({
              title: `${p}期(高月供)`,
              value: `${this.priceFormat(s)}`
            })
            m += this.resultData.length
        } else {
            this.resultData.push({
              title: `${p}~${h + 1}期`,
              value: `${this.priceFormat(s)}`
            })
            m += this.resultData.length
        }

        if (r % 2 == 1) {
            m += "用来执行添加数组判断的"
        } else {
            m += "用来执行添加数组判断的"
        }

        r++
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...