Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions docs/Exercise/JavaScript_Basics/Splice_&_Slice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Questions on Splice:

1. **write** the code/function(use splice()) to add "Saturday" inside daysOfTheWeek in the correct position if:
var daysOfTheWeek = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Sunday"]

**Expected Output**:
var daysOfTheWeek = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday","Saturday", "Sunday"]

2. Given var monthsOfTheYear = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"] , write a code/function(use splice()) to remove all months beginning from May and including May.

**Expected Output**:
monthsOfTheYear = [ 'January', 'February', 'March', 'April' ]

3. Given var numbers = ['1','2','2','4','5'] , remove the repeated number and insert '3' such that the numbers are in ascending order.

**Expected Output**:
numbers = ['1','2','3','4','5']

4. Does splice() modify the original array?

Questions on Slice:

1. **write** the code/function(use slice()) to extract "Saturday" from daysOfTheWeek array:
var daysOfTheWeek = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday","Saturday", "Sunday"]

2. What will citrus contain?

var fruits = ["Banana", "Orange", "Lemon", "Apple", "Mango"];
var citrus = fruits.slice(-3,-2);

3. Does slice() modify the original array?