Created
October 26, 2020 04:08
-
-
Save remydagostino/0b0a98f4f98741fde9bd6dcb1b48aac6 to your computer and use it in GitHub Desktop.
Social Beverage Programme
This file contains 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
// Usage: node matcher.js people-list.txt 2 | |
const people = require('fs').readFileSync(process.argv[2]).toString().split('\n'); | |
const weekNum = Number(process.argv[3]); | |
const pairs = people | |
.map((person, index) => people[(index + weekNum) % people.length]) | |
.map((person, index, list) => { | |
const match = list[list.length - index - 1]; | |
if (match === person) { | |
return [person, list[0]]; | |
} else { | |
return [person, match]; | |
} | |
}) | |
.map(pair => weekNum % 2 ? pair.reverse() : pair) | |
.slice(0, Math.floor((people.length + 1) / 2)); | |
console.log(pairs.map(pair => pair.join(' -> ')).join('\n')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment