Skip to content

Commit 437119d

Browse files
committed
studio
1 parent 18fc274 commit 437119d

14 files changed

+3797
-16
lines changed

arrays/studio/array-string-conversion/array-testing.js

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,47 @@ strings = [protoArray1, protoArray2, protoArray3, protoArray4];
88
//2)
99
function reverseCommas() {
1010
//TODO: 1. create and instantiate your variables.
11-
let check;
12-
let output;
11+
let check = strings[0];
12+
let output = [];
1313
//TODO: 2. write the code required for this step
14+
if (check.includes(",")){
15+
output = check.split(",").reverse().join(",");
16+
}
1417

1518
//NOTE: For the code to run properly, you must return your output. this needs to be the final line of code within the function's { }.
1619
return output;
1720
}
1821

1922
//3)
2023
function semiDash() {
21-
let check;
22-
let output;
23-
//TODO: write the code required for this step
24-
25-
24+
let check = strings[1];
25+
let output = [];
26+
//TODO: 2. write the code required for this step
27+
if (check.includes(";")){
28+
output = check.split(";").reverse().join(";");
29+
}
2630
return output;
2731
}
2832

2933
//4)
3034
function reverseSpaces() {
31-
let check;
32-
let output;
33-
//TODO: write the code required for this step
34-
35+
let check = strings[2];
36+
let output = [];
37+
//TODO: 2. write the code required for this step
38+
if (check.includes(" ")){
39+
output = check.split(" ").reverse().join(" ");
40+
}
3541
return output;
3642
}
3743

3844
//5)
3945
function commaSpace() {
40-
let check;
41-
let output;
42-
//TODO: write the code required for this step
43-
46+
let check = strings[3];
47+
let output = [];
48+
//TODO: 2. write the code required for this step
49+
if (check.includes(", ")){
50+
output = check.split(", ").reverse().join(", ");
51+
}
4452
return output;
4553
}
4654

arrays/studio/multi-dimensional-arrays.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,38 @@ let pets = "parrots,cats,moose,alien eggs";
44
let sleepAids = "blankets,pillows,eyepatches,alarm clocks";
55

66
//1) Use split to convert the strings into four cabinet arrays. Alphabetize the contents of each cabinet.
7+
cabinet1 = food.split(",").sort();
8+
cabinet2 = equipment.split(",").sort();
9+
cabinet3 = pets.split(",").sort();
10+
cabinet4 = sleepAids.split(",").sort();
11+
712

813
//2) Initialize a cargoHold array and add the cabinet arrays to it. Print cargoHold to verify its structure.
914

15+
cargoHold = [cabinet1, cabinet2, cabinet3, cabinet4];
16+
17+
console.log(cargoHold);
18+
19+
1020
//3) Query the user to select a cabinet (0 - 3) in the cargoHold.
21+
const input = require('readline-sync');
22+
let numCabinet = input.question(`Please select a cabinet number between 0 and ${cargoHold.length -1}: `);
1123

1224
//4) Use bracket notation and a template literal to display the contents of the selected cabinet. If the user entered an invalid number, print an error message.
13-
25+
if (numCabinet > cargoHold.length -1 || numCabinet < 0){
26+
console.log(`Error, enter valid number between 0 and ${cargoHold.length -1}.`);
27+
} else {
28+
console.log(`The selected cabinet contains: ${cargoHold[numCabinet]}.`)
29+
}
1430
//5) Modify the code to query the user for BOTH a cabinet in cargoHold AND a particular item. Use the 'includes' method to check if the cabinet contains the selected item, then print “Cabinet ____ DOES/DOES NOT contain ____.”
31+
32+
let item = input.question(`Select an item from ${cargoHold[numCabinet]}: `);
33+
if (numCabinet > cargoHold.length -1 || numCabinet < 0){
34+
console.log(`Error, enter valid number between 0 and ${cargoHold.length -1}.`);
35+
}else {
36+
if (numCabinet > (cargoHold[numCabinet].includes(item))){
37+
console.log(`Cabinet ${numCabinet} DOES contain ${item}.`)
38+
} else {
39+
console.log(`Cabinet ${numCabinet} DOES NOT contain ${item}.`)
40+
}
41+
}

arrays/studio/node_modules/.package-lock.json

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

arrays/studio/node_modules/readline-sync/LICENSE-MIT

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

arrays/studio/node_modules/readline-sync/README-Deprecated.md

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

0 commit comments

Comments
 (0)