Skip to content

Commit e65941b

Browse files
authored
Completed part 4
1 parent 43c2ba7 commit e65941b

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

arrays/exercises/part-four-arrays.js

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,30 @@
11
let holdCabinet1 = ['duct tape', 'gum', 3.14, false, 6.022e23];
22
let holdCabinet2 = ['orange drink', 'nerf toys', 'camera', 42, 'parsnip'];
33

4-
//Explore the methods concat, slice, reverse, and sort to determine which ones alter the original array.
4+
// 1) Print the result of using concat on the two arrays. Does concat alter the original arrays? Verify this by printing holdCabinet1 after using the method.
5+
let combinedCabinet = holdCabinet1.concat(holdCabinet2);
6+
console.log(combinedCabinet);
7+
// ['duct tape', 'gum', 3.14, false, 6.022e23, 'orange drink', 'nerf toys', 'camera', 42, 'parsnip']
8+
console.log(holdCabinet1);
9+
// ['duct tape', 'gum', 3.14, false, 6.022e23] - concat does not alter the original array.
510

6-
//1) Print the result of using concat on the two arrays. Does concat alter the original arrays? Verify this by printing holdCabinet1 after using the method.
11+
// 2) Print a slice of two elements from each array. Does slice alter the original arrays?
12+
let sliceCabinet1 = holdCabinet1.slice(1, 3);
13+
let sliceCabinet2 = holdCabinet2.slice(2, 4);
14+
console.log(sliceCabinet1);
15+
// ['gum', 3.14]
16+
console.log(sliceCabinet2);
17+
// ['camera', 42]
18+
console.log(holdCabinet1);
19+
// ['duct tape', 'gum', 3.14, false, 6.022e23] - slice does not alter the original array.
20+
console.log(holdCabinet2);
21+
// ['orange drink', 'nerf toys', 'camera', 42, 'parsnip'] - slice does not alter the original array.
722

8-
//2) Print a slice of two elements from each array. Does slice alter the original arrays?
23+
// 3) Reverse the first array, and sort the second. What is the difference between these two methods? Do the methods alter the original arrays?
24+
holdCabinet1.reverse();
25+
console.log(holdCabinet1);
26+
// [6.022e23, false, 3.14, 'gum', 'duct tape'] - reverse alters the original array.
927

10-
//3) reverse the first array, and sort the second. What is the difference between these two methods? Do the methods alter the original arrays?
28+
holdCabinet2.sort();
29+
console.log(holdCabinet2);
30+
// [42, 'camera', 'nerf toys', 'orange drink', 'parsnip'] - sort alters the original array.

0 commit comments

Comments
 (0)