0
0
Swiftprogramming~10 mins

Array operations (append, insert, remove) in Swift - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add a new element to the end of the array.

Swift
var fruits = ["Apple", "Banana"]
fruits.[1]("Orange")
Drag options to blanks, or click blank then click option'
Aremove
Binsert
CpopLast
Dappend
Attempts:
3 left
💡 Hint
Common Mistakes
Using insert without specifying an index.
Trying to remove instead of add.
2fill in blank
medium

Complete the code to insert an element at the start of the array.

Swift
var numbers = [2, 3, 4]
numbers.[1](1, at: 0)
Drag options to blanks, or click blank then click option'
Aappend
Binsert
Cremove
DpopLast
Attempts:
3 left
💡 Hint
Common Mistakes
Using append which always adds at the end.
Using remove which deletes elements.
3fill in blank
hard

Complete the code to remove the element "Banana" from the array.

Swift
var fruits = ["Apple", "Banana", "Cherry"]
fruits.[1](at: 1)
Drag options to blanks, or click blank then click option'
Aremove
Bappend
Cinsert
DpopLast
Attempts:
3 left
💡 Hint
Common Mistakes
Using append or insert which add elements instead of removing.
Using popLast which removes the last element, not a specific one.
4fill in blank
hard

Fill both blanks to insert "Grape" at index 2 and then remove the element at index 0.

Swift
var fruits = ["Apple", "Banana", "Cherry"]
fruits.[1]("Grape", at: 2)
fruits.[2](at: 0)
Drag options to blanks, or click blank then click option'
Ainsert
Bappend
Cremove
DpopLast
Attempts:
3 left
💡 Hint
Common Mistakes
Using append instead of insert for adding at a specific index.
Using popLast instead of remove(at:) for removing at a specific index.
5fill in blank
hard

Fill all three blanks to append "Kiwi", insert "Mango" at index 1, and remove the last element.

Swift
var fruits = ["Apple", "Banana"]
fruits.[1]("Kiwi")
fruits.[2]("Mango", at: 1)
fruits.[3]()
Drag options to blanks, or click blank then click option'
Aremove
Bappend
Cinsert
DpopLast
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up append and insert.
Using remove() without index to remove last element.