Reverse a string - not accepting correct solution
See original GitHub issueChallenge Reverse a String has an issue.
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36
.
Please describe how to reproduce this issue, and include links to screenshots if possible.
I can complete the assignment with unshift but wanted to create this function to reuse in the other algorithm challenges. My output seems correct but is not registering as being correct.
My code:
function reverseString(str) {
var retstr="";
var l=str.length;
for (var i=0; i<str.length; i++){
retstr+=(str[l-i-1]);
}
retstr="\""+retstr+"\"";
return retstr;
}
reverseString("Howdy");
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Reverse a string without affecting special characters
Given a string, that contains a special character together with alphabets ('a' to 'z' and 'A' to 'Z'), reverse the string in a...
Read more >Leetcode Reverse String problem not accepting in-place ...
As I understand, both solutions are in-place. However, solution 1 is not accepted and prompts as wrong answer. Solution 2 is accepted. Could ......
Read more >Reverse String - LeetCode
Write a function that reverses a string. The input string is given as an array of characters s . You must do this...
Read more >Reverse a String - Four JavaScript Solutions
The reverse a string problem is a common algorithm problem. In this article, we will consider four JavaScript solutions to it.
Read more >Reverse String | LeetCode 344 | C++, Java, Python - YouTube
LeetCode Solutions : https://www.youtube.com/playlist?list=PL1w8k37X_6L86f3PUUVFoGYXvZiZHde1SJune LeetCoding Challenge: ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think your line
retstr="\""+retstr+"\"";
is the problem. There is no need to add the double quotes around the reversed string.Yeah, that is not the correct solution @tgardiner88 For
reverseString("Howdy");
, your function returns""ydwoH""
, when it should return"ydwoH"