Skip to content

Instantly share code, notes, and snippets.

@wotjd
Created July 22, 2019 07:01
Show Gist options
  • Save wotjd/8bd1f7565d3b66d18d7ead63e1c2434c to your computer and use it in GitHub Desktop.
Save wotjd/8bd1f7565d3b66d18d7ead63e1c2434c to your computer and use it in GitHub Desktop.
let intArray = [1,2,3,4,5]
// using for loop
var forResult = [Int]()
for num in intArray {
forResult.append(num + 1)
}
print(forResult) // [2,3,4,5,6]
// using map
var mapResult = intArray.map { $0 + 1 }
print(mapResult) // [2,3,4,5,6]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment