2018-01-29 A simple script for shuffling exam questions

As we approach the end of the semester, my free time shrinks to nearly zero. Today I’m only going to share a simple tip. Last week, I prepared an exam. I wanted 10 questions, each one taken from one chapter of the lecture. I also wanted 6 sets (4 for the exam and 2 for the retake). And I wanted no bias (even unconscious) – problem sets for the retake should be neither easier nor harder than for the first attempt etc.

So, for each chapter I prepared six questions, making an array of arrays of six strings. Since I’ve been mostly working in JavaScript recently, I decided to do it in using this language. (JS is often being looked down on, which is a shame. It has a terrible, terrible syntax, almost on the level of Java-terrible, but really nice semantics. Basically speaking, it is a Lisp with a C-like syntax with a few moronic additions.) So, my data looked like this:

let questions = [
	[
		'What is JavaScript?',
		'Why is JavaScript a great language?',
		'Why is JavaScript a terrible language?',
		'What is the nicest thing in JavaScript, and why closures?',
		'What is the most stupid problem with JavaScript, and why ASI?',
		'What is the difference between Java and JavaScript?',
	],
	[
		'...',
		'...',
		'...',
		'...',
		'...',
		'...',
	],
	[
		'...',
		'...',
		'...',
		'...',
		'...',
		'...',
	],
];

I thought that my task won’t be very difficult, but I was pleasantly surprised by the fact that it was so easy. Unsurprisingly, I used the popular Lodash library:

const _ = require('lodash');

sets = _.zip(..._.map(questions, _.shuffle));

_.each(sets, set => {
	_.each(set, q => {
		console.log(`\\item ${q}\n`);
	});
	console.log('\n\n');
});

As you can see, the shuffling is done in just one line, using ES6’s spread operator (which is in a sense the JS’s analogue of Lisp’s apply); the rest of the code is sending the results to stdout in a form suitable for inclusion in a LaTeX file (after manually adding the enumerate environment, of course). And that’s it!

CategoryEnglish, CategoryBlog, CategoryJavaScript