I wrote a JS constructor which reverse a string variable:
function ReverseString(string) {
this.str = string;
var size = this.str.length;
this.reverse = function () {
for(size; size >= 0; --size) {
console.log(this.str[size]);
}
}
}
When I invoke a reverse method on a new string object("asd") it produces the following output:
undefined
d
s
a
Where this undefined came from? Could you help me eliminate this ?
str.split("").reverse().join("")is an useful idiom.ReverseStringwith a single purpose in life which is to reverse the string it holds? You plan to reverse it again and again?