On Mon, Dec 13, 2010 at 2:24 PM, Gary Katsevman <[email protected]>wrote:

> > I were able to apply your suggestion within
> > the "next" method, but not with the "prev". Would you like to share
> > version of the methods?
>
> I just realized that the prev method won't be as easy. JavaScript does
> not respect negative modulo. So,
>  -2 % 5 // -2 in JS
> rather than the 3 we are expecting.
>
> So, doing this.array[this.position-- % this.array.length] is a naive
> implementation that does not take that into account.
> Instead you can do this.array[((this.position-- + this.array.length) +
> this.array.length)].
>

I don't think that would be more efficient (or any easier to read) than the
original implementation.
-Peter

-- 
You received this message because you are subscribed to the Google Groups "The 
JSMentors JavaScript Discussion Group" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/jsmentors?hl=en.

Reply via email to