Tell us what’s happening:
This isn’t a post to ask for help as this solution works. My question is, after looking at the “Get A Hint” feature to check my reasoning, another way was suggested.
Now, to the author’s credit, it works and it’s much more elegant and concise. However, from a student’s perspective, it doesn’t make sense as the solution requires knowledge of methods that were not covered. Whereas, my solution (albeit in a clunkier way) not only passes the challenge, but it more iterative of what a complete beginner using no other resources might come up with based on the knowledge covered. Any chances of having such solutions given for these types of problems?
It’s already done quite often, but I know I am not alone in feeling discouraged when the the challenge asks a question and the answer is given in a completely different way.
Your code so far
function reverseString(str) {
let reverse = [];
for (let i = str.length; i >= 0; i--){
reverse.push(str[i])
}
console.log(reverse) //returns ,h,t,r,a,E, ,m,o,r,f, ,s,g,n,i,t,e,e,r,G
return reverse.join("")
}
console.log(reverseString("Greetings from Earth"));
//returns 'htraE morf sgniteerG'
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/reverse-a-string/