Kris Kindle / Secret Santa the Groovy Way

In efforts to explain to folks in the office how secret santa works I directed them to take a look at this secret santa definition or alternatively to examine the following groovy code:


def ezbPeeps = User.findByCompanyName('eazybusiness')
def hatOfNames = ezbPeeps.collect{it.name}
ezbPeeps.each { peep ->

def goodPick = null
while(!goodPick){
def randomInteger = RandomInteger.getGenerate()
assert randomInteger > 0
def index = randomInteger%hatOfNames.size()
switch( hatOfNames[index] ){
case peep.name:
goodPick = false
break
default:
goodPick = true
print "${peep.name} gets ${hatOfNames[index]}"
hatOfNames.remove(index)
break
}
}
}

mistakes on a postcard to Eamonn O'Connell, Saasplex, 3015 Lake View
Drive, Citywest, Dublin, Ireland

Comments

Popular posts from this blog

AngularJs: User friendly date display with AngularJs and MomentJs

Getting started with Grails functional tests using Geb + Spock

Nerd Tree: A File Explorer with Mac Vim