loverajoel / jstips

This is about useful JS tips!
http://jstips.co
GNU General Public License v3.0
12.5k stars 803 forks source link

make-easy-loop-on-array #327

Closed jamet-julien closed 8 years ago

jamet-julien commented 8 years ago

Make easy loop on array

TL;DR;

Make a elegant loop on array

Username

Julien jamet: github

zenopopovici commented 8 years ago

@jamet-julien: Please use english.

jamet-julien commented 8 years ago

Is it better ?

zenopopovici commented 8 years ago

@jamet-julien There is a bit of work to do maybe the others can chime in ...

jamet-julien commented 8 years ago

@zenopopovici Thanks. Is it good now?

zenopopovici commented 8 years ago

@jamet-julien Thanks Julien, we will be adding this under review soon. We still have some backlog of tips proposals. When it is under review, more people will chime in and suggest changes. We'll ping you when that happens.

jamet-julien commented 8 years ago

@zenopopovici Thanks.

gromgit commented 8 years ago

@jamet-julien A few general comments:

function make_looper( arr ) {

  // Internal index to track next item to return
  arr.loop_idx = ???;  // your start index would be determined by whether
                  // next() and prev() are post- or pre-incremental

  // Return next item in loop
  arr.next = function() {
    // ...
  }

  // Return previous item in loop
  arr.prev = function() {
    // ...
  }

}

// example of pre-incrementing loop
var aList = ['A','B','C', 'D', 'E'];
aList.prev();  // -> E
aList.next();  // -> A
aList.next();  // -> B
loverajoel commented 8 years ago

@gromgit really nice feedback

jamet-julien commented 8 years ago

@gromgit thank. I look this and update the code.

gromgit commented 8 years ago

@jamet-julien Much better now, although the first sentence is still rather vague. I suggest something like this instead:

Sometimes, we need to loop endlessly over an array of items, like a carousel of images or an audio playlist. Here's how to take an array and give it "looping powers":

jamet-julien commented 8 years ago

@gromgit better, isn't it ?

gromgit commented 8 years ago

@jamet-julien :+1:

jamet-julien commented 8 years ago

@loverajoel thanks, is it Ok ?

loverajoel commented 8 years ago

@jamet-julien you have my :shipit:

zenopopovici commented 8 years ago

Mine too :shipit:

jamet-julien commented 8 years ago

@loverajoel Can you tell me what is the next step please. Could I do modification ? thank.

loverajoel commented 8 years ago

@JakeRawr we need 5 shipits to merge this, I'll try merge this week

ppollo07 commented 8 years ago

:shipit: 🐔

aschelstraete commented 8 years ago

:shipit: 🎱

sjfkai commented 8 years ago

:shipit: 👍

cjkumaresh commented 8 years ago

:shipit:

pklinger commented 8 years ago

:shipit: