Programmed Canon Canola calculators in 1977. Assorted platforms and languages ever since. Assisting with HOPL.info.
I am NOT looking for work -- I've got more than enough to do.
Location
Perth, WA Australia
Education
A few diplomas.
Work
Software Engineer at [Daisy Digital](https://daisydigital.com.au/)
This recursion thing is pretty cool. Here's another approach both as a String.prototype and as a standalone function:
String.prototype.flip2 = function() {
if (1 >= this.length) return this;
return (
this.substr(-1) +
this.substr(1, this.length - 2).flip2() +
this.substr(0, 1)
);
};
function flip2(string) {
if (1 >= string.length) return string;
return (
string.substr(-1) +
flip2(string.substr(1, string.length - 2)) +
string.substr(0, 1)
);
}
var x = "lewd i did live - evil did i dwel".flip2();
var y = flip2("lewd i did live - evil did i dwel");
The approach is to take the first character and put it last, take the last character and put it first, and do that to the stuff in the middle.
It's been through the Closure Compiler, thus the 1 >= this.length.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
This recursion thing is pretty cool. Here's another approach both as a String.prototype and as a standalone function:
The approach is to take the first character and put it last, take the last character and put it first, and do that to the stuff in the middle.
It's been through the Closure Compiler, thus the
1 >= this.length
.