Skip to content

Commit 802b94e

Browse files
committed
studio functions complete
1 parent 5eac592 commit 802b94e

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

functions/studio/studio-functions.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,19 @@
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+
function reverseCharacters(s){
12+
if (typeof(s) == 'string') {
13+
return s.split('').reverse().join('');
14+
}
15+
else if (typeof(s) == 'number') {
16+
let stringNumber = s.toString();
17+
let arrayNumber = stringNumber.split('');
18+
let reversedArray = arrayNumber.reverse();
19+
let stringNumber2 = reversedArray.join('');
20+
return Number(stringNumber2);
21+
}
22+
}
23+
console.log(reverseCharacters("potato"));
1124

1225
// Part Two: Reverse Digits
1326

@@ -30,6 +43,18 @@ let arrayTest1 = ['apple', 'potato', 'Capitalized Words'];
3043
let arrayTest2 = [123, 8897, 42, 1168, 8675309];
3144
let arrayTest3 = ['hello', 'world', 123, 'orange'];
3245

46+
function reverseArray(arrayTest){
47+
let newArray = [];
48+
for (let i = 0; i < arrayTest.length; i++) {
49+
newArray.unshift(reverseCharacters(arrayTest[i]))
50+
}
51+
return newArray;
52+
}
53+
54+
console.log(reverseArray(arrayTest1));
55+
console.log(reverseArray(arrayTest2));
56+
console.log(reverseArray(arrayTest3));
57+
3358
// Bonus Missions
3459

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

0 commit comments

Comments
 (0)