# Swift's closure
#   https://d...content-available-to-author-only...e.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Closures.html


DigitNames = {
    0 => "Zero", 1 => "One", 2 => "Two",   3 => "Three", 4 => "Four",
    5 => "Five", 6 => "Six", 7 => "Seven", 8 => "Eight", 9 => "Nine"
}
Numbers = [16, 58, 510]


strings = Numbers.map { |number|
    loop.inject([number, '']) { |(num, output), _|
        if num > 0
            [num / 10, DigitNames[num % 10] + output]
        else
            break output
        end
    }
}


for s in strings
    puts s
end