Created
February 8, 2018 13:53
-
-
Save dimatarelkin/925dfb569536cd5d968edbc9ca580324 to your computer and use it in GitHub Desktop.
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
let digitNames = [ | |
0: "Zero", 1: "One", 2: "Two", 3: "Three", 4: "Four", | |
5: "Five", 6: "Six", 7: "Seven", 8: "Eight", 9: "Nine" | |
] | |
let numbers = [124] | |
let strings = numbers.map { (number) -> String in | |
var number = number | |
var output = "" | |
repeat { | |
if let digit = digitNames[number % 10] { | |
output = digit + output //справа налево | |
number /= 10 | |
} | |
} while number > 0 | |
return output | |
} | |
print(strings) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment