+ 1
can someone explain this part please(short code)
Part i dont understand: repeat { output = digitNames[number % 10]! + output number /= 10 } while number > 0 WHOLE CODE: let digitNames = [ 0: "Zero", 1: "One", 2: "Two", 3: "Three", 4: "Four", 5: "Five", 6: "Six", 7: "Seven", 8: "Eight", 9: "Nine" ] let numbers = [16, 58, 510] let strings = numbers.map { (number) -> String in var number = number var output = "" repeat { output = digitNames[number % 10]! + output number /= 10 } while number > 0 return output } print(strings) // strings is inferred to be of type [String] // its value is ["OneSix", "FiveEight", "FiveOneZero"]
2 Answers
0
just repeating the stmt with modulo 10(reminder after dividing by 10) and dividing by 10 to get to each numbers(left to right) and concating.
for 16
output = dN[1]+dN[6]
first dN[6] and concatinated it to dN[1].
0
Dzondzula did it understand this?