Skip to content

Commit 6f2d996

Browse files
brians arrays and strings
1 parent 695a55a commit 6f2d996

File tree

7 files changed

+39
-34
lines changed

7 files changed

+39
-34
lines changed

arrays/exercises/package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

arrays/exercises/part-five-arrays.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
let str = 'In space, no one can hear you code.';
22
let arr = ['B', 'n', 'n', 5];
3-
4-
//1) Use the split method on the string to identify the purpose of the parameter inside the ().
5-
6-
//2) Use the join method on the array to identify the purpose of the parameter inside the ().
7-
8-
//3) Do split or join change the original string/array?
9-
10-
//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.
3+
console.log(str.split());
4+
console.log(str.split('e'));
5+
console.log(str.split(' '));
6+
console.log(str.split(''));
117
let cargoHold = "water,space suits,food,plasma sword,batteries";
8+
cargoHold.join("water,space suits,food,plasma sword,batteries");
9+
console.log(cargoHold);

arrays/exercises/part-four-arrays.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
let holdCabinet1 = ['duct tape', 'gum', 3.14, false, 6.022e23];
22
let holdCabinet2 = ['orange drink', 'nerf toys', 'camera', 42, 'parsnip'];
3+
console.log(holdCabinet1.concat(holdCabinet2));
4+
console.log(holdCabinet1);
5+
holdCabinet1.reverse();
6+
console.log(holdCabinet1);
7+
holdCabinet2.sort();
8+
console.log(holdCabinet2)
39

410
//Explore the methods concat, slice, reverse, and sort to determine which ones alter the original array.
511

arrays/exercises/part-one-arrays.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
//Create an array called practiceFile with the following entry: 273.15
2-
3-
//Use the bracket notation method to add "42" and "hello" to the array. Add these new items one at a time. Print the array after each step to confirm the changes.
4-
5-
//Use a single .push() to add the following items: false, -4.6, and "87". Print the array to confirm the changes.
1+
let practiceFile = [273.15];
2+
practiceFile.push(42);
3+
practiceFile.push("hello");
4+
console.log(practiceFile);
5+
practiceFile.push(false, -4.6, "87")
6+
console.log(practiceFile);

arrays/exercises/part-six-arrays.js

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
//Arrays can hold different data types, even other arrays! A multi-dimensional array is one with entries that are themselves arrays.
2-
3-
//1) Define and initialize the arrays specified in the exercise to hold the name, chemical symbol and mass for different elements.
4-
5-
//2) Define the array 'table', and use 'push' to add each of the element arrays to it. Print 'table' to see its structure.
6-
7-
//3) Use bracket notation to examine the difference between printing 'table' with one index vs. two indices (table[][]).
8-
9-
//4) Using bracket notation and the table array, print the mass of element1, the name for element 2 and the symbol for element26.
10-
11-
//5) 'table' is an example of a 2-dimensional array. The first “level” contains the element arrays, and the second level holds the name/symbol/mass values. Experiment! Create a 3-dimensional array and print out one entry from each level in the array.
1+
let element1 = ['hydrogen', 'H', 1.008];
2+
let element2 = ['helium', 'He', 4.003];
3+
let element26 = ['iron', 'Fe', 55.85];
4+
console.log(table[1], table[1][1]);

arrays/exercises/part-three-arrays.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
let cargoHold = [1138, 'space suits', 'parrot', 'instruction manual', 'meal packs', 'space tether', '20 meters'];
2+
cargoHold.splice(3,0,'keys');
3+
console.log(cargoHold);
4+
cargoHold.splice(3,'instruction manual');
5+
console.log(cargoHold);
6+
cargoHold.splice(2,3,'cat','fob','string cheese');
7+
console.log(cargoHold);
28

39
//Use splice to make the following changes to the cargoHold array. Be sure to print the array after each step to confirm your updates.
410

arrays/exercises/part-two-arrays.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
let cargoHold = ['oxygen tanks', 'space suits', 'parrot', 'instruction manual', 'meal packs', 'slinky', 'security blanket'];
2-
3-
//1) Use bracket notation to replace ‘slinky’ with ‘space tether’. Print the array to confirm the change.
4-
5-
//2) Remove the last item from the array with pop. Print the element removed and the updated array.
6-
7-
//3) Remove the first item from the array with shift. Print the element removed and the updated array.
8-
9-
//4) Unlike pop and shift, push and unshift require arguments inside the (). Add the items 1138 and ‘20 meters’ to the the array - the number at the start and the string at the end. Print the updated array to confirm the changes.
10-
11-
//5) Use a template literal to print the final array and its length.
2+
cargoHold[5] = 'space tether';
3+
console.log(cargoHold);
4+
console.log(cargoHold.shift('oxygen tanks'));
5+
console.log(cargoHold);
6+
console.log(`The array ${cargoHold} has a length of ${cargoHold.length}.`);

0 commit comments

Comments
 (0)