Skip to content

Commit 878593a

Browse files
committed
Reversing a String
1 parent 6d723fc commit 878593a

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

ReverseAString.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Given a string, reverse it!
3+
*/
4+
5+
// This can be solved by splitting the string into an array. split("")
6+
// Reversing the array, then joining it back together. reverse().join("")
7+
8+
const reverseString = inputString => {
9+
return inputString.split("").reverse().join("")
10+
}
11+
12+
console.log(reverseString("Stefan"))
13+
console.log(reverseString("Lamario"))
14+
console.log(reverseString("Bayne"))
15+
16+
/**
17+
* Output:
18+
*
19+
* nafetS
20+
* oiramaL
21+
* enyaB
22+
*/

0 commit comments

Comments
 (0)