Could somewone help with the code. It should return reversed array.
var reverseString = function(s) {
if(s.length == 1) return s[0];
if(s.length > 1) {
return (s.pop() + reverseString(s)).split('');
}
}
reverseString(["h","e","l","l","o"]); //outputs ["o", "l", ",", "l", ",", ",", ",", "e", ",", ",", ",", ",", ",", ",", ",", "h"]if I change return value
return (s.pop() + reverseString(s)) ;
reverseString(["h","e","l","l","o"]); //outputs string ollehbut the length of the string is strange:
return (s.pop() + reverseString(s)).length ;
reverseString(["h","e","l","l","o"]); //outputs 2I'm confused with this situation, and cann't figure out what is wrong...