Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to insert a value at the beginning of the array.
DSA Typescript
let arr = [2, 3, 4]; arr.[1](1); console.log(arr);
Attempts:
3 left
💡 Hint
Common Mistakes
Using push instead of unshift, which adds at the end.
Using pop or shift which remove elements instead of adding.
✗ Incorrect
The unshift method adds an element to the start of the array.
2fill in blank
mediumComplete the code to insert the number 0 at the beginning of the array.
DSA Typescript
const numbers = [1, 2, 3]; numbers.[1](0); console.log(numbers);
Attempts:
3 left
💡 Hint
Common Mistakes
Using push which adds at the end.
Using pop or shift which remove elements.
✗ Incorrect
unshift adds the element at the start of the array.
3fill in blank
hardFix the error in the code to insert 'start' at the beginning of the array.
DSA Typescript
let items = ['middle', 'end']; items.[1]('start'); console.log(items);
Attempts:
3 left
💡 Hint
Common Mistakes
Using push instead of unshift.
Using pop or shift which remove elements.
✗ Incorrect
Use unshift to add an element at the beginning.
4fill in blank
hardFill both blanks to create an array with 0 at the beginning and 4 at the end.
DSA Typescript
let arr = [1, 2, 3]; arr.[1](0); arr.[2](4); console.log(arr);
Attempts:
3 left
💡 Hint
Common Mistakes
Using push to add at the start.
Using pop or shift which remove elements.
✗ Incorrect
unshift adds at the start, push adds at the end.
5fill in blank
hardFill all three blanks to insert 'first' at start, remove last element, then add 'last' at end.
DSA Typescript
let list = ['middle']; list.[1]('first'); list.[2](); list.[3]('last'); console.log(list);
Attempts:
3 left
💡 Hint
Common Mistakes
Using shift instead of pop to remove last element.
Using push instead of unshift to add at start.
✗ Incorrect
unshift adds at start, pop removes last, push adds at end.
