Skip to content

Instantly share code, notes, and snippets.

@dewey
Created December 16, 2014 21:36
Show Gist options
  • Save dewey/341585f0a27178a20502 to your computer and use it in GitHub Desktop.
Save dewey/341585f0a27178a20502 to your computer and use it in GitHub Desktop.
var input = ['p1', 'p2', 'p3', 'p4', 'p5', 'p6']
var output = [];
var counter = 0;
for(var i = 0; i <= input.length-1; i++) {
var tupel = [];
if(counter == 0) {
tupel.push(input[i])
counter++;
}
if(i == (counter - 1)) {
tupel.push(input[i+1])
output.push(tupel)
}
if(counter < i) {
tupel = [];
tupel.push(input[counter])
tupel.push(input[i])
output.push(tupel)
counter++;
}
}
console.log(output)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment