Interview Question: Write a JavaScript function to reverse / flip an incoming string.
Created
August 22, 2013 16:25
-
-
Save KatieK2/6309512 to your computer and use it in GitHub Desktop.
Reverse the String
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
| <h1>Reverse the String</h1> | |
| <h2>My Awesome String</h2> |
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() { | |
| var theString = $("h2").text(); | |
| var revString = ""; | |
| for (var i=theString.length; i>0; i--) | |
| { | |
| revString = revString + theString.charAt(i-1); | |
| } | |
| $("h2").text(revString); | |
| }); |
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
| h1, h2, p { margin: 1rem; } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment