var test = "SURESH";
test.split("").reverse().join("");
Output
======
"HSERUS"
function reverse(s) {
var o = '';
for (var i = s.length - 1; i >= 0; i--)
o += s[i];
return o;
}
reverse('SURESH');
Output
======
"HSERUS"
function reverse(s) {
var o = [];
for (var i = s.length - 1, j = 0; i >= 0; i--, j++) {
o[j] = s[i];
}
return o.join('');
}
reverse('SURESH');
Output
======
"HSERUS"
function reverse(s) {
var o = [];
for (var i = 0, len = s.length; i <= len; i++) {
o.push(s.charAt(len - i));
}
return o.join('');
}
reverse('SURESH');
Output
======
"HSERUS"
function reverse(s) {
return (s === '') ? '' : reverse(s.substr(1)) + s.charAt(0);
}
reverse('SURESH');
Output
======
"HSERUS"