Skip to content

Commit f99e54b

Browse files
studio done
1 parent 28c556a commit f99e54b

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,24 @@ strings = [protoArray1, protoArray2, protoArray3, protoArray4];
99
function reverseCommas() {
1010
//TODO: 1. create and instantiate your variables.
1111
let check;
12-
let output;
12+
let output = protoArray1.split(",").reverse().join(",");
1313
//TODO: 2. write the code required for this step
14-
1514
//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 { }.
1615
return output;
1716
}
1817

1918
//3)
2019
function semiDash() {
2120
let check;
22-
let output;
21+
let output = protoArray2.split(";").sort().join("-");
2322
//TODO: write the code required for this step
24-
25-
2623
return output;
2724
}
2825

2926
//4)
3027
function reverseSpaces() {
3128
let check;
32-
let output;
29+
let output = protoArray3.split(" ").sort().reverse().join(" ");
3330
//TODO: write the code required for this step
3431

3532
return output;
@@ -38,7 +35,7 @@ function reverseSpaces() {
3835
//5)
3936
function commaSpace() {
4037
let check;
41-
let output;
38+
let output = protoArray4.split(", ").reverse().join(", ");
4239
//TODO: write the code required for this step
4340

4441
return output;
@@ -51,4 +48,4 @@ module.exports = {
5148
semiDash: semiDash,
5249
reverseSpaces : reverseSpaces,
5350
commaSpace : commaSpace
54-
};
51+
};

arrays/studio/string-modification.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,20 @@ let str = "LaunchCode";
33

44
//1) Use string methods to remove the first three characters from the string and add them to the end.
55
//Hint - define another variable to hold the new string or reassign the new string to str.
6+
let strModified = str.replace("Lau", "") + str.slice(0, 3);
67

78
//Use a template literal to print the original and modified string in a descriptive phrase.
9+
console.log(`Original String ${str} \nModified String ${strModified}`);
810

911
//2) Modify your code to accept user input. Query the user to enter the number of letters that will be relocated.
12+
let userInput = input.question("Enter number of letter to relocate: ");
1013

1114
//3) Add validation to your code to deal with user inputs that are longer than the word. In such cases, default to moving 3 characters. Also, the template literal should note the error.
15+
let defult = 3;
16+
if (userInput > str.length) {
17+
strModified = str.slice(defult, str.length) + str.slice(0, defult);
18+
console.log(`Input number is longer than characters in word. Defaulting to 3\n${strModified}`);
19+
} else {
20+
strModified = str.slice(userInput, str.length) + str.slice(0, userInput);
21+
console.log(strModified);
22+
}

0 commit comments

Comments
 (0)