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:
mistakes on a postcard to Eamonn O'Connell, Saasplex, 3015 Lake View
Drive, Citywest, Dublin, Ireland
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
Post a Comment