When I call this function, sending for example: abc as the parameter, the function returns: undefinedcba. I can't figure out why it's adding 'undefined' to my returned value. I'm probably overlooking something obvious but I can't spot it. Thank you.
function FirstReverse(str) {
var str_arr1 = new Array();
var ans = '';
for(i=0; i < str.length; i++) {
str_arr1.push(str.charAt(i));
}
for(j=str.length; j >= 0; j--) {
ans += str_arr1[j];
}
return ans;
}