Skip to content

Instantly share code, notes, and snippets.

@hvgotcodes
Created July 17, 2012 00:41
Show Gist options
  • Save hvgotcodes/3126160 to your computer and use it in GitHub Desktop.
Save hvgotcodes/3126160 to your computer and use it in GitHub Desktop.
calculateScore: ->
totalToPar = 0
holes = @get 'holes'
score = 0
outScore = 0
outToPar = 0
inScore = 0
inToPar = 0
for hole in holes
holeScore = hole.getPath 'details.length'
holeNumber = hole.get 'number'
score += holeScore if holeScore
par = hole.get 'par'
totalToPar += (holeScore - par) if par.length and holeScore
if 9 >= holeNumber >= 1
outScore += holeScore if holeScore
outToPar += holeScore - par if par.length and holeScore
else
inScore += holeScore if holeScore
inToPar += holeScore - par if par.length and holeScore
@set 'totalScore', score
@set 'totalToPar', totalToPar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment