题解 | #求二次方#
求二次方
https://www.nowcoder.com/practice/b7a8647e33d84f5c88acdd7c81a85fdf
function square(arr) { //for //let res=arr; //for(let i=0;i<arr.length;i++){ // res[i]=Math.pow(arr[i],2) //} //for of //let res=[] //for(let num of arr){ // res.push(Math.pow(num,2)) //} //return res; //forEach //let res=[] //arr.forEach(num=>{ // res.push(Math.pow(num,2)) //}) //return res; //map最简洁 return arr.map(num=>Math.pow(num,2))