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(function(number) {
  13. output = ""
  14. while (number > 0) {
  15. output = digitNames[(number % 10).toString()] + output
  16. number = Math.floor(number / 10)
  17. }
  18.  
  19. return output
  20. })
  21.  
  22.  
  23. for (i = 0; i < strings.length; i++) {
  24. print(strings[i])
  25. }
Success #stdin #stdout 0.01s 4984KB
stdin
Standard input is empty
stdout
OneSix
FiveEight
FiveOneZero