题解 | #求二次方#

求二次方

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))

全部评论

相关推荐

喝干太平洋:我是大专 我感觉我当时的简历比你好点 就一个vue吗
点赞 评论 收藏
分享
06-04 09:27
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务