Last active
January 23, 2022 21:25
-
-
Save abdullahoguk/cb0dd2fa736192859dc51a4ead66c8e2 to your computer and use it in GitHub Desktop.
Split the array into pairs in JavaScript wit Array Reduce
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var arr = [1,5,6,7,4,8,5]; | |
arr.reduce((previous, current, index, array)=>{ | |
return index%2==0 ? [...previous, array.slice(index,index+2)] : previous | |
},[]) | |
//>[[1,5],[6,7],[4,8],[5]] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment