Created
June 8, 2014 15:01
-
-
Save RonJeffries/b0ce26229e668f122fc8 to your computer and use it in GitHub Desktop.
Swift Lang tuples another way
This file contains 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
// might like this as better use of Tuple. Not sure. Return Tuple, use its named elements | |
// code is asking for a frame object, i think, but wanted to try Tuples | |
func frameScore(index:Int) -> (score: Int, step: Int) { | |
if isStrike(index) { | |
return (rolls[index] + twoRolls(index+1), 1) | |
} else if isSpare(index) { | |
return (twoRolls(index) + rolls[index+2], 2) | |
} else { | |
return (twoRolls(index), 2) | |
} | |
} | |
func score() -> Int { | |
var sum = 0 | |
var index = 0 | |
for frame in 1...10 { | |
let frameInfo = frameScore(index) | |
sum += frameInfo.score | |
index += frameInfo.step | |
} | |
return sum | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use the tuples in score, why not?