javascript - Encapsulate the repeated parts of these two functions into one function?
大家讲道理
大家讲道理 2017-05-19 10:09:46
0
3
512
//给数组中的每一项增加3

function addThreeForEachItem(array){

      for(var i = 0; i < array.length; i++){

        array[i] = array[i] + 3;

    }

    return array;

}

//将数组中的每一项编码

function encodeEachItem(array){

    for(var i = 0; i < array.length; i++){

        array[i] = encodeURIComponent(array[i]);

    }

    return array;

}

The two functions are very similar (duplicate). How to encapsulate the repeated parts of these two functions into one function?

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!