Skip to content

Instantly share code, notes, and snippets.

@sebdeckers
Created November 20, 2015 00:36
Show Gist options
  • Save sebdeckers/2f5aaed55dde3a33c10a to your computer and use it in GitHub Desktop.
Save sebdeckers/2f5aaed55dde3a33c10a to your computer and use it in GitHub Desktop.
function arguments: array destructuring vs spread operator
var combos = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
/* function destructures arguments */
function checkWinning ([x, y, z]) {
console.log(x, y, z)
}
combos.forEach(checkWinning)
/* pass arguments one by one with spread */
function checkWinning (x, y, z) {
console.log(x, y, z)
}
combos.forEach(combo => checkWinning(...combo))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment