You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: functions/studio/studio-functions.js
+58Lines changed: 58 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,7 @@
1
1
//We want to COMPLETELY reverse an array by flipping the order of the entries AND flipping the order of characters in each element.
2
2
3
+
const{ text }=require("stream/consumers");
4
+
3
5
// Part One: Reverse Characters
4
6
5
7
// 1. Define the function as reverseCharacters. Give it one parameter, which will be the string to reverse.
@@ -9,6 +11,36 @@
9
11
// 5. Use console.log(reverseCharacters(myVariableName)); to call the function and verify that it correctly reverses the characters in the string.
10
12
// 6. Optional: Use method chaining to reduce the lines of code within the function.
11
13
14
+
15
+
/*function reverseCharacters(text) {
16
+
newText = text.split("");
17
+
newText.reverse();
18
+
newText = newText.join("");
19
+
return newText;
20
+
}
21
+
22
+
let textSample = "Dorea"
23
+
console.log(reverseCharacters(textSample));*/
24
+
25
+
letstringToReverse="Tank";
26
+
27
+
functionreverseCharacters(str){
28
+
lettmpArr=[];
29
+
if(typeofstr==="string"){
30
+
tmpArr=str.split("");
31
+
tmpArr.reverse();
32
+
str=tmpArr.join("");
33
+
}elseif(typeofstr==="number"){
34
+
str=String(str);
35
+
str=reverseCharacters(str);
36
+
}
37
+
returnstr;
38
+
}
39
+
40
+
41
+
//return str.split("").reverse().join("");
42
+
43
+
12
44
// Part Two: Reverse Digits
13
45
14
46
// 1. Add an if statement to reverseCharacters to check the typeof the parameter.
@@ -17,6 +49,12 @@
17
49
// 4. Return the reversed number.
18
50
// 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
51
52
+
53
+
54
+
55
+
56
+
57
+
20
58
// Part Three: Complete Reversal - Create a new function with one parameter, which is the array we want to change. The function should:
0 commit comments