On Sun, May 8, 2011 at 1:48 PM, austincheney
<[email protected]> wrote:
> If an object index on a string is actually valid then you can use
> this:
>
> String.prototype.customSplit = function (x) {
>    var a,
>        b,
>        c = this.length,
>        d = x.length,
>        e,
>        f = [],
>        g = [];
>    for (a = 0; a < c; a += 1) {
>        if (d > 1) {
>            for (b = a; b < d; b += 1) {
>                e.push(this[b]);
>            }
>            e.join("");
>        } else {
>            e = this[a];
>        }
>        if (e !== x) {
>            f.push(this[a]);
>        } else {
>            g.push(f.join(""));
>            f = [];
>        }
>    }
>    for (; a < c; a += 1) {
>        f.push(this[a]);
>    }
>    g.push(f.join(""));
>    return g;
> };
>

Really nice ! ++

As and extra exercise it would be great trying to completely avoid
".push()" and ".join()" calls and have a pure Javascript API
independent code ;-)

Surely ".push()" will be easier to avoid than ".join()", but I believe
a nested loop will make them both doable.

--
Diego


> Otherwise, I do not believe there is any valid solution.  Personally,
> I
> will continue using the charAt method for the foreseeable future.
>
> Austin Cheney
> http://prettydiff.com/
>
> --
> To view archived discussions from the original JSMentors Mailman list: 
> http://www.mail-archive.com/[email protected]/
>
> To search via a non-Google archive, visit here: 
> http://www.mail-archive.com/[email protected]/
>
> To unsubscribe from this group, send email to
> [email protected]
>

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to