hey guys I understand that the following will work for reversing a string passed to the function:
function reverseString(str) {
return str.split('').reverse().join('');
}
reverseString("hello");
however can someone help me understand why the following won't work?
function reverseString(str) {
str.split(' ');
str.reverse();
str.join(' ');
return str;
}
"Hi! 😁".split('').reverse().join('');won't give the expected output (if your font doesn't have support: the last chacter is the emoji at U+1F601 which gets translated into two characters which need the correct order to work). So if you want to use it you have to take care that the input is restricted or use a packet made for it, e.g.: npmjs.com/package/esrever which was just the first Google spit out.