fork download
  1. # Swift's closure
  2. # https://d...content-available-to-author-only...e.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Closures.html
  3.  
  4.  
  5. DigitNames = {
  6. 0 => "Zero", 1 => "One", 2 => "Two", 3 => "Three", 4 => "Four",
  7. 5 => "Five", 6 => "Six", 7 => "Seven", 8 => "Eight", 9 => "Nine"
  8. }
  9. Numbers = [16, 58, 510]
  10.  
  11.  
  12. strings = Numbers.map { |number|
  13. output = ''
  14. while number > 0
  15. output = DigitNames[number % 10] + output
  16. number /= 10
  17. end
  18.  
  19. output
  20. }
  21.  
  22.  
  23. for s in strings
  24. puts s
  25. end
Success #stdin #stdout 0.02s 7412KB
stdin
Standard input is empty
stdout
OneSix
FiveEight
FiveOneZero