Skip to content

Instantly share code, notes, and snippets.

@tranhieutt
Last active July 4, 2017 08:04
Show Gist options
  • Save tranhieutt/813f2a7a0b311a8294113b72c28a34b5 to your computer and use it in GitHub Desktop.
Save tranhieutt/813f2a7a0b311a8294113b72c28a34b5 to your computer and use it in GitHub Desktop.
[Swift] - map - extension
let scores :[NSNumber] = [0,28,124]
let words = scores.map {NumberFormatter.localizedString(from: $0, number:.spellOut) }
print(words)
//Console: ["zero", "twenty-eight", "one hundred twenty-four"]
//
let milesToPoint = ["Point1":120.0,"Point2":45.0,"Point3":55.0]
let kmToPoint = milesToPoint.map{name,miles in miles*1.67}
//console: [200.39999999999998, 75.149999999999991, 91.849999999999994]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment