Skip to content

Commit 59b0872

Browse files
committed
all three completed
1 parent b765aab commit 59b0872

File tree

1 file changed

+35
-7
lines changed

1 file changed

+35
-7
lines changed

functions/studio/studio-functions.js

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,55 @@
88
// 4. Below the function, define and initialize a variable to hold a string.
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.
11-
1211
// Part Two: Reverse Digits
13-
1412
// 1. Add an if statement to reverseCharacters to check the typeof the parameter.
1513
// 2. If typeof is ‘string’, return the reversed string as before.
1614
// 3. If typeof is ’number’, convert the parameter to a string, reverse the characters, then convert it back into a number.
17-
// 4. Return the reversed number.
15+
// 4. Return the reversed number
1816
// 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.
19-
2017
// Part Three: Complete Reversal
2118

19+
20+
function reverseCharacters(original){
21+
let reverse = '';
22+
if(typeof original === String){
23+
reverse = original.split('').reverse().join('');
24+
}
25+
else if(typeof original !== String){
26+
reverse = original.toString().split('').reverse().join('');
27+
28+
} else{
29+
console.log("nothing else");
30+
}
31+
32+
return reverse;
33+
}
34+
console.log(reverseCharacters("apples"));
35+
2236
// 1. Define and initialize an empty array.
2337
// 2. Loop through the old array.
38+
39+
let arrayTest1 = ['apple', 'potato', 'Capitalized Words'];
40+
let arrayTest2 = [123, 8897, 42, 1168, 8675309];
41+
let arrayTest3 = ['hello', 'world', 123, 'orange'];
42+
43+
function doubleReverse(originalArray){
44+
let oldArray = [];
45+
46+
for(i = 0; i < originalArray.length; i++){
47+
oldArray.push(reverseCharacters(originalArray[i]));
48+
49+
} return oldArray.reverse();
50+
}
51+
console.log(doubleReverse(arrayTest3));
52+
53+
2454
// 3. For each element in the old array, call reverseCharacters to flip the characters or digits.
2555
// 4. Add the reversed string (or number) to the array defined in part ‘a’.
2656
// 5. Return the final, reversed array.
2757
// 6. Be sure to print the results from each test case in order to verify your code.
2858

29-
let arrayTest1 = ['apple', 'potato', 'Capitalized Words'];
30-
let arrayTest2 = [123, 8897, 42, 1168, 8675309];
31-
let arrayTest3 = ['hello', 'world', 123, 'orange'];
59+
3260

3361
// Bonus Missions
3462

0 commit comments

Comments
 (0)