After making the LineUp class that can be iterated starting with 1 (Zero is for programmers) Customers start at ONE.
Now I want the iterator to wrap around... like a team that bats around the line up... ?so into the Modulo arithmetic...
I'm doing this experiment in a Swift Xcode Playground... so not to sure about how to do unit testing inside the Playground???
indexWrapped <= 0 ?? index = indexMax : index = indexWrapped - 1
give 2 errors:?Cannot assign to value: result of conditional operator '? :' is never mutable. ?Result values in '? :' expression have mismatching types '()' and 'Int'
?
Now can anyone put this is simple caveman logic... seems like a perfectly good place to use my most hated ? :?operation. ?I don't GROK.
?
class LineUp {
? ? var lineup = ["Bob", "Tony", "Iris", "Jane", "Nan", "Dave", "George", "Ringo", "Shannon" ]
?? ?
? ? subscript(n: Int) -> String {
? ? ? ? var index = 0
? ? ? ? let indexMax = lineup.count
? ? ? ? let indexWrapped = n % indexMax
? ? ? ? indexWrapped <= 0 ?? index = indexMax : index = indexWrapped - 1
? ? ? ? return lineup[index]
? ? }
}
?
?