Array Manipulation in Swift
Level 269 keystrokes
Adds an element at the end with append and at the beginning with insert(_:at:), then prints [0, 1, 2, 3, 4].
Swift code
// var is required so the array can be changed1var nums = [1, 2, 3]// append adds 4 at the end: [1, 2, 3, 4]2nums.append(4)// Insert the value 0 at index 0 (the first argument is the value)3nums.insert(0, at: 0)// Prints [0, 1, 2, 3, 4]4print(nums)Output
[0, 1, 2, 3, 4]
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this Swift code and how often they appear.
,× 3(× 3)× 3.× 2:× 1[× 1]× 1=× 1