File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ All of these examples are from FreeCodeCamp's [course](https://www.freecodecamp.
1212
1313- [ Basic Algorithm Scripting] ( #basic-algorithm-scripting )
1414 - [ 1. Convert Celsius to Fahrenheit] ( #1-convert-celsius-to-fahrenheit )
15+ - [ 2. Reverse a String] ( #2-reverse-a-tring )
1516
1617## Basic Algorithm Scripting
1718
@@ -35,3 +36,40 @@ function convertToF(celsius) {
3536
3637convertToF(30);
3738```
39+
40+ ### 2. Reverse a String
41+
42+ ### Difficulty: Beginner
43+
44+ Reverse the provided string.
45+
46+ You may need to turn the string into an array before you can reverse it.
47+
48+ Your result must be a string.
49+
50+ ---
51+
52+ ### Solution 1
53+
54+ ```
55+ function reverseString(str) {
56+ return str.split("").reverse().join("");
57+ }
58+
59+ reverseString("hello");
60+ ```
61+
62+ ### Solution 2
63+
64+ ```
65+ function reverseString(str) {
66+ let reversedString = "";
67+ for (let i = str.length - 1; i >= 0; i--) {
68+ reversedString += str[i];
69+ }
70+ return reversedString;
71+ }
72+
73+ reverseString("hello");
74+
75+ ```
You can’t perform that action at this time.
0 commit comments