Skip to content

Commit 2b1fb2d

Browse files
committed
ArraysExercisesPt3
1 parent a31644f commit 2b1fb2d

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

arrays/exercises/part-three-arrays.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ let cargoHold = [1138, 'space suits', 'parrot', 'instruction manual', 'meal pack
33
//Use splice to make the following changes to the cargoHold array. Be sure to print the array after each step to confirm your updates.
44

55
//1) Insert the string 'keys' at index 3 without replacing any other entries.
6-
6+
cargoHold.splice(3,0, 'keys');
7+
console.log(cargoHold)
78
//2) Remove ‘instruction manual’ from the array. (Hint: indexOf is helpful to avoid manually counting an index).
8-
9+
console.log(cargoHold.indexOf('instruction manual'))
10+
cargoHold.splice(4,1)
11+
console.log(cargoHold)
912
//3) Replace the elements at indexes 2 - 4 with the items ‘cat’, ‘fob’, and ‘string cheese’.
13+
console.log(cargoHold.indexOf('parrot'));
14+
cargoHold.splice(2,3,'cat','fob', 'string cheese');
15+
console.log(cargoHold);

arrays/exercises/part-two-arrays.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ console.log(`Anytime you perform a check for take off, the cargohold should read
1818

1919
/*/Status check, rookie. Which array methods ADD items, and where are the new entries placed? Which methods REMOVE items,
2020
and where do the entries come from? Which methods require entries inside the ()?//*/
21-
//-array methods that add an item are "splice", "unshift" and "push". methods that remove items, are: "pop" and "shift".//
21+
//-array methods that add an item are "splice", "unshift" and "push". methods that remove items, are: "pop", "splice" and "shift".//

0 commit comments

Comments
 (0)