前端面试笔试程序题

2019-10-24  本文已影响0人  致青春永恒

1,假如有一个数组[1,2,3,4,5,6],封装一个方法将数组奇偶换位[2,1,4,3,6,5]。

        functionchange(a){

            varcount;

            a.forEach((item,index)=>{

                    if(index%2==0){

                        count=a[index]

                    }else{

                      a[index-1]=item;a

                      [index]=count

                 }

        });

    returna;

    }

2,有一个数组A[1,2,3,4,5,6],数组B[a,b,c],经过变换后[1,2,a,3,4,b,5,6,c],封装一个函数。

        vararr1=[1,2,3,4,5,6];vararr2=["a",'b','c'];functioncheck(a,b,c){b.forEach((item,index)=>{if(c){a.splice(index+(index+1)*c,0,item)}else{a.splice(index+(index+1)*2,0,item)}});returna}varres=check(arr1,arr2)console.log(res)

求数组的最大值

letarr=[1,2,8,3,5,6];varmax=Math.max(...arr)console.log(max)//8

上一篇 下一篇

猜你喜欢

热点阅读