+ 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"]

3rd Dec 2020, 2:49 AM
Dzondzula
Dzondzula - avatar
2 Respuestas
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].
3rd Dec 2020, 8:22 AM
Ashok Acharya
Ashok Acharya - avatar
0
Dzondzula did it understand this?
3rd Dec 2020, 6:30 PM
Ashok Acharya
Ashok Acharya - avatar