Skip to content

Commit 66970e9

Browse files
committed
studio 4? 5 maybe? functions
1 parent 3136856 commit 66970e9

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

functions/studio/studio-functions.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,24 @@
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 tempStr = String(str)
14+
let spltStr = tempStr.split("");
15+
let tempArray = [];
16+
for (let i = 0; i < tempStr.length; i++){
17+
tempArray.push(tempStr[-i + tempStr.length -1]);
18+
}
19+
let finalReversed = tempArray.join("");
20+
if (typeof str === Number) {
21+
Number(finalReversed);
22+
}
23+
24+
return finalReversed;
25+
}
26+
27+
let testString = 123456789;
28+
console.log(reverseCharacters(testString));
29+
1230
// Part Two: Reverse Digits
1331

1432
// 1. Add an if statement to reverseCharacters to check the typeof the parameter.
@@ -19,6 +37,15 @@
1937

2038
// Part Three: Complete Reversal
2139

40+
function completeReversal(Arr) {
41+
newArray = [];
42+
for (let i = 0; i < Arr.length; i++) {
43+
newArray.push(reverseCharacters(Arr[-i + Arr.length -1]));
44+
}
45+
return newArray;
46+
}
47+
48+
2249
// 1. Define and initialize an empty array.
2350
// 2. Loop through the old array.
2451
// 3. For each element in the old array, call reverseCharacters to flip the characters or digits.
@@ -29,7 +56,7 @@
2956
let arrayTest1 = ['apple', 'potato', 'Capitalized Words'];
3057
let arrayTest2 = [123, 8897, 42, 1168, 8675309];
3158
let arrayTest3 = ['hello', 'world', 123, 'orange'];
32-
59+
console.log(completeReversal(arrayTest3));
3360
// Bonus Missions
3461

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

0 commit comments

Comments
 (0)