> 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)]. ------------------------ Gary Katsevman Computer Science Undergraduate Northeastern University gkatsev.com On Mon, Dec 13, 2010 at 14:17, Leonardo Braga <[email protected]> wrote: > Hi Gary, > > Thanks for your comment. > > Leonardo Braga > @LeonardoBraga > > > On Dec 13, 5:04 pm, Gary Katsevman <[email protected]> wrote: >> > this.next = function() { >> > (!(++this.position < this.array.length)) && (this.position >> > = 0); >> > return this.array[this.position]; >> > } >> >> Why not use modulo on the position and return >> this.array[this.position++ % this.array.length] for next and -- for >> prev? >> >> ------------------------ >> Gary Katsevman >> Computer Science Undergraduate >> Northeastern University >> gkatsev.com > > -- > 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. > > -- 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.
