Last active
August 29, 2015 14:16
-
-
Save rodrigoalviani/977351b31da2c14b9b72 to your computer and use it in GitHub Desktop.
Match pairs - array based
This file contains hidden or 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
'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