Skip to content

Commit 9073d26

Browse files
committed
Studio complete
1 parent 704c4e7 commit 9073d26

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
.DS_Store
1+
.DS_Store
2+
**/node_modules

functions/studio/studio-functions.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@
99
// 5. Use console.log(reverseCharacters(myVariableName)); to call the function and verify that it correctly reverses the characters in the string.
1010
// 6. Optional: Use method chaining to reduce the lines of code within the function.
1111

12+
// function reverseCharacters(str){
13+
// let reversedArray = str.split('').reverse()
14+
15+
// return reversedArray.join('')
16+
// }
17+
// function reverseCharacters(str){
18+
// return reversedArray = str.split('').reverse().join('')
19+
// }
20+
// let testVariable = "Vincent";
21+
22+
// console.log(reverseCharacters(testVariable));
23+
1224
// Part Two: Reverse Digits
1325

1426
// 1. Add an if statement to reverseCharacters to check the typeof the parameter.
@@ -17,6 +29,17 @@
1729
// 4. Return the reversed number.
1830
// 5. Be sure to print the result returned by the function to verify that your code works for both strings and numbers. Do this before moving on to the next exercise.
1931

32+
function reverseCharacters(str){
33+
if (typeof str === 'string') {
34+
return reversedArray = str.split('').reverse().join('')
35+
} else if (typeof str === 'number') {
36+
let reversedNumber = String(str).split('').reverse().join('');
37+
let num = Number(reversedNumber);
38+
return num
39+
}
40+
}
41+
42+
2043
// Part Three: Complete Reversal
2144

2245
// 1. Define and initialize an empty array.
@@ -30,6 +53,18 @@ let arrayTest1 = ['apple', 'potato', 'Capitalized Words'];
3053
let arrayTest2 = [123, 8897, 42, 1168, 8675309];
3154
let arrayTest3 = ['hello', 'world', 123, 'orange'];
3255

56+
function reverseArray(inputArray){
57+
let newArray = [];
58+
for (let i = 0; i < inputArray.length; i++) {
59+
newArray.push(reverseCharacters(inputArray[i]));
60+
}
61+
return newArray.reverse();
62+
}
63+
64+
console.log(reverseArray(arrayTest1));
65+
console.log(reverseArray(arrayTest2));
66+
console.log(reverseArray(arrayTest3));
67+
3368
// Bonus Missions
3469

3570
// 1. Have a clear, descriptive name like funPhrase.

loops/exercises/for-Loop-Exercises.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@
2727
let newStr = "LaunchCode";
2828
let newArray = [1, 5, 'LC101', 'blue', 42];
2929

30-
Construct ``for`` loops to accomplish the following tasks:
31-
a. Print each element of the array to a new line.
30+
// Construct ``for`` loops to accomplish the following tasks:
31+
// a. Print each element of the array to a new line.
3232

3333
for (i=0; i < newArray.length; i ++){
3434
console.log(newArray[i]);
3535
}
36-
b. Print each character of the string - in reverse order - to a new line.
36+
// b. Print each character of the string - in reverse order - to a new line.
3737

3838
for (let i = newStr.length -1; i >=0; i--){
3939
console.log(newStr[i]);

0 commit comments

Comments
 (0)