x = [1, 2, 3, 4]
t = []
c = []
for(i = 0; i<x.length; i++){
function solution(){
t = Math.pow(x, 2)
c = t[i]++
return c
}
}
该功能需要:
答案 0 :(得分:1)
const result = [1, 2, 3, 4].map(n => n ** 2).reduce((acc, val) => acc + val, 0);
console.log(result);
**
更快的Math.pow()
运算符。 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
答案 1 :(得分:0)
var result = [1, 2, 3, 4].map(n => Math.pow(n, 2)).reduce((acc, val) => acc + val, 0);
console.log(result);