week7
This commit is contained in:
parent
b66439390c
commit
e473695a8a
15
week7/package.json
Normal file
15
week7/package.json
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "final_presentation_randomizer",
|
||||
"version": "1.0.0",
|
||||
"description": "produces a randomized presentation schedule",
|
||||
"main": "schedule.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "gauthier",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"chance": "^1.0.4",
|
||||
"commander": "^2.9.0"
|
||||
}
|
||||
}
|
||||
70
week7/schedule.js
Normal file
70
week7/schedule.js
Normal file
@ -0,0 +1,70 @@
|
||||
/*
|
||||
file: schedule.js
|
||||
desc: simple script that produces a randomized presentation schedule
|
||||
author: gauthier
|
||||
date: 14/12/16
|
||||
*/
|
||||
|
||||
// import 'commander' (https://www.npmjs.com/package/commander)
|
||||
var program = require('commander');
|
||||
|
||||
// import chance (http://chancejs.com)
|
||||
var chance = require('chance').Chance(); // npm install --save chance
|
||||
|
||||
// initialise program (aka commander)
|
||||
program
|
||||
.version('0.1')
|
||||
.option('-g, --group [string]', 'Group to schedule', 'empty')
|
||||
.parse(process.argv);
|
||||
|
||||
|
||||
var groups = [
|
||||
|
||||
[
|
||||
"Rahul & Randy",
|
||||
"Inés & John",
|
||||
"Cecilie & Joanna",
|
||||
"Eva & Nicole",
|
||||
"Lenka, Vivien and Laura",
|
||||
],
|
||||
[
|
||||
"Julia & Johanna",
|
||||
"Martin & Bram",
|
||||
"Wietske, Dave & Judith",
|
||||
"Annabel & Maxim",
|
||||
"Cassandra & Léna"
|
||||
]
|
||||
];
|
||||
|
||||
function choice(array) {
|
||||
var index = chance.natural({'min': 0, 'max': array.length - 1}); // **** NOTE: 'max': array.length - 1
|
||||
return array[index];
|
||||
}
|
||||
|
||||
function schedule(array) {
|
||||
var i = 1;
|
||||
while(array.length > 0) {
|
||||
var c = choice(array);
|
||||
console.log(' ' + i++ + '. ' + c);
|
||||
array.splice(array.indexOf(c),1);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
console.log('\n\n\n\n');
|
||||
switch(program.group)
|
||||
{
|
||||
case '01':
|
||||
console.log('Final presentation CTH-2016 Group 01\n');
|
||||
schedule(groups[0]);
|
||||
break;
|
||||
case '02':
|
||||
console.log('Final presentation CTH-2016 Group 02\n');
|
||||
schedule(groups[1]);
|
||||
break;
|
||||
default:
|
||||
'Nothing...';
|
||||
}
|
||||
console.log('\n\n\n\n');
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user