Answers for "create pair foreach item in array"

0

create pair foreach item in array

arr = [1, 2, 3, 4];

function pairwise(arr, func){
    for(var i=0; i < arr.length - 1; i++){
        func(arr[i], arr[i + 1])
    }
}

pairwise(arr, function(current, next){
    console.log(current, next)
})
Posted by: Guest on October-10-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language