Skip to content

Commit

Permalink
minor lints
Browse files Browse the repository at this point in the history
  • Loading branch information
clux committed Jun 24, 2021
1 parent efc75be commit e06186b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 4 additions & 2 deletions robin.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ module.exports = function (n, ps) { // n = num players
for (let i = 0; i < n / 2; i += 1) {
const o = n - 1 - i;
if (ps[i] !== DUMMY && ps[o] !== DUMMY) {
const iHome = i === 0 && j % 2 === 1;
rs[j].push([iHome ? ps[o] : ps[i], iHome ? ps[i] : ps[o]]); // insert pair as a match - [ away, home ]
// flip orders to ensure everyone gets roughly n/2 home matches
const isHome = i === 0 && j % 2 === 1;
// insert pair as a match - [ away, home ]
rs[j].push([isHome ? ps[o] : ps[i], isHome ? ps[i] : ps[o]]);
}
}
ps.splice(1, 0, ps.pop()); // permutate for next round
Expand Down
6 changes: 3 additions & 3 deletions test/robin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var $ = require('interlude')
test('robin', function *(t) {
$.range(20).forEach(function (n) {
var rs = robin(n);
var expected = ($.odd(n)) ? n : n-1;
var expected = $.odd(n) ? n : n-1;
t.eq(expected, rs.length, 'correct number of rounds');

var pMaps = [];
Expand Down Expand Up @@ -75,7 +75,7 @@ test('home-away', function *(t) {
}
}

for (let i = 1; i <= n; i++) {
for (let i = 1; i <= n; i += 1) {
const isOddPlayer = i % 2 === 1;
const fairAmount = (n - 1) / 2;
const [ roundedUp, roundedDown ] = [ Math.ceil(fairAmount), Math.floor(fairAmount) ];
Expand All @@ -95,4 +95,4 @@ test('home-away', function *(t) {

hasCorrectHomeAwayOutput(9);
hasCorrectHomeAwayOutput(10);
})
});

0 comments on commit e06186b

Please sign in to comment.