Tell us what’s happening:
Cant figure out how to keep the original spaces in the last check mark: reverseString(“Greetings from Earth”) should return “htraE morf sgniteerG”
Your code so far
function reverseString(str) {
let res = [];
let res2 = [];
res = [...str.split("")];
let love;
res2.push(res.pop());
res2.push(res.pop());
res2.push(res.pop());
res2.push(res.pop());
res2.push(res.pop());
//console.log(res2);
//console.log(res2.join(''));
str = res2.join('');
console.log(str);
return str;
}
reverseString("hello");
Your browser information:
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/reverse-a-string