Skip to content

Commit cf53d18

Browse files
committed
ArraysExercisesPt5
1 parent 14d2156 commit cf53d18

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

arrays/exercises/part-five-arrays.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,29 @@
11
let str = 'In space, no one can hear you code.';
22
let arr = ['B', 'n', 'n', 5];
3-
3+
let newP = [];
44
//1) Use the split method on the string to identify the purpose of the parameter inside the ().
5-
5+
newP = str.split();
6+
console.log(newP);
7+
newP = str.split('e');
8+
console.log(newP);
9+
newP = str.split(' ');
10+
console.log(newP);
11+
newP = str.split('');
12+
console.log(newP);
613
//2) Use the join method on the array to identify the purpose of the parameter inside the ().
7-
14+
newP = arr.join();
15+
console.log(newP);
16+
newP = arr.join('a');
17+
console.log(newP);
18+
newP = arr.join(' ');
19+
console.log(newP);
20+
newP = arr.join('');
21+
console.log(newP);
822
//3) Do split or join change the original string/array?
923

24+
// neither will not change the original, and it will need to run under a new "array"//
25+
1026
//4) We can take a comma-separated string and convert it into a modifiable array. Try it! Alphabetize the cargoHold string, and then combine the contents into a new string.
1127
let cargoHold = "water,space suits,food,plasma sword,batteries";
28+
29+
console.log(cargoHold.split(',').sort().join());

0 commit comments

Comments
 (0)