题解 | #求二次方#

求二次方

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

全部评论

相关推荐

Twilight_m...:经典我朋友XXXX起手,这是那种经典的不知道目前行情搁那儿胡编乱造瞎指导的中年人,不用理这种**
点赞 评论 收藏
分享
05-16 11:16
已编辑
东华理工大学 Java
牛客73769814...:盲猜几十人小公司,庙小妖风大,咋不叫她去4️⃣呢😁
牛客创作赏金赛
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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