Skip to content

Instantly share code, notes, and snippets.

@pbalduino
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pbalduino/dbde66fb9e4b51f7d7d9 to your computer and use it in GitHub Desktop.
Save pbalduino/dbde66fb9e4b51f7d7d9 to your computer and use it in GitHub Desktop.
// Expectation: [1, 8, 6, 4, 3, 5, 7, 2]
var teams = [1, 2, 3, 4, 5, 6, 7, 8];
var matches = [];
for(var pos = 0; pos < teams.length / 2; pos++)
{
var even = pos % 2 === 0;
var ta = teams[pos];
var tb = teams[(teams.length - 1) - pos];
matches.push(even ? ta : tb);
matches.push(even ? tb : ta);
}
console.log(matches);
// got: [1, 8, 7, 2, 3, 6, 5, 4]
// exp: [1, 8, 6, 4, 3, 5, 7, 2] =(
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment