Created
March 4, 2015 17:26
-
-
Save rodrigoalviani/8ecea216aabebe14d3d4 to your computer and use it in GitHub Desktop.
Match pairs - array based (with typed groups)
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 | |
, defender = [] | |
, attacker = [] | |
, len = Math.max(defender.length, attacker.length); | |
function mathPair () { | |
return selectName(defender) + ' & ' + selectName(attacker); | |
} | |
function selectName (arr) { | |
var name = arr[Math.floor((Math.random() * arr.length))]; | |
if (name === undefined) { | |
return '__________'; | |
} else { | |
arr.splice(arr.indexOf(name), 1); | |
return name; | |
} | |
} | |
for (i = 0; i < len; i++) | |
console.log('#' + (i + 1) + ' ' + mathPair()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment