Skip to content

Instantly share code, notes, and snippets.

@Nicktho
Created August 29, 2016 11:53
Show Gist options
  • Save Nicktho/1196f0ab822cc1b452e02be231fc941f to your computer and use it in GitHub Desktop.
Save Nicktho/1196f0ab822cc1b452e02be231fc941f to your computer and use it in GitHub Desktop.
function addToQueue(...people) {
var positions = []
for (var i = 0; i < people.length; i++) {
positions[i] = function() {
return i + 1
}
}
return positions
}
var queuePositions = addToQueue('Greg', 'Charlie', 'Anna')
console.log(queuePositions[0]()) // 4
console.log(queuePositions[1]()) // 4
console.log(queuePositions[2]()) // 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment