Created
January 20, 2020 18:44
-
-
Save Giagnus64/76e2a18cd63b81b3e6422e1a577be7b0 to your computer and use it in GitHub Desktop.
Reverse Broken Down
This file contains hidden or 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
| function reverse(str){ | |
| // if we arrive at the final character of the string, return that character | |
| if (str.length === 1) return str[0]; | |
| //otherwise return the last character of the string, plus the reverse function called on a sliced version of that string | |
| return str[str.length - 1] + reverse(str.slice(0, str.length - 1)) | |
| } | |
| //1st Call returns "r" + reverse("ba") | |
| //2nd call "a" + reverse("b") | |
| //3rd Call "b" | |
| //returns "r" + "a" + "b" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment