Swift - Write program to convert number to English word

Requirements

Write program to convert number to English word

Given an array of single-digit integers, write the code snippet to return the English equivalent of each integer:

Hint

var numbers = [5,6,3,2,4,8,1,0]

should output:

[Five, Six, Three, Two, Four, Eight, One, Zero]

Demo

let numNames =  [
    0: "Zero",/*from   w w  w  .j  a v  a 2  s  . co m*/
    1: "One",
    2: "Two",
    3: "Three",
    4: "Four",
    5: "Five",
    6: "Six",
    7: "Seven",
    8: "Eight",
    9 : "Nine"
]
var numbers = [5,6,3,2,4,8,1,0]
var numbersNames = numbers.map (
    {
        (num: Int) -> String in
            return numNames [num]!
    }
)
print(numbersNames)

Result

Related Exercise