Last active
August 29, 2015 14:20
-
-
Save pbalduino/dbde66fb9e4b51f7d7d9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 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