Skip to content

Instantly share code, notes, and snippets.

@rodrigoalviani
Last active August 29, 2015 14:16
Show Gist options
  • Save rodrigoalviani/977351b31da2c14b9b72 to your computer and use it in GitHub Desktop.
Save rodrigoalviani/977351b31da2c14b9b72 to your computer and use it in GitHub Desktop.
Match pairs - array based
'use strict';
var i = 0
, names = [] // add names here
, len = (names.length / 2);
function matchPair () {
return selectName() + ' & ' + selectName();
}
function selectName () {
var name = names[Math.floor((Math.random() * names.length))];
if (name === undefined) {
return '__________';
} else {
names.splice(names.indexOf(name), 1);
return name;
}
}
for (i = 0; i < len; i++)
console.log('#' + (i + 1) + ' ' + matchPair());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment