Created
February 10, 2022 16:53
-
-
Save dev-sampsonorson/4be794a895c030b8902c06dc452c9b67 to your computer and use it in GitHub Desktop.
Recursive implementation to reverse a string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let input = "engineer at ProDevs"; | |
const reverse = (data) => { | |
if (data.length === 1) | |
return data; | |
return data[data.length - 1] + reverse(data.slice(-data.length, -1)); | |
} | |
console.log(reverse(input)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment