Closed jamet-julien closed 8 years ago
@jamet-julien: Please use english.
Is it better ?
@jamet-julien There is a bit of work to do maybe the others can chime in ...
@zenopopovici Thanks. Is it good now?
@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.
@zenopopovici Thanks.
@jamet-julien A few general comments:
index
is part of the looping state of aList
, it really should be a property of aList
(i.e. aList.index
) rather than a separate variable.change()
function does a pre-increment, so the first change()
call actually returns aList[1]
, i.e. B
.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
E
in the above example, then someone calls aList.pop()
twice, so aList == ['A','B','C']
. How do you properly handle the next aList.next()
or aList.prev()
? (Your original change()
function doesn't handle this correctly either.)@gromgit really nice feedback
@gromgit thank. I look this and update the code.
@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":
@gromgit better, isn't it ?
@jamet-julien :+1:
@loverajoel thanks, is it Ok ?
@jamet-julien you have my :shipit:
Mine too :shipit:
@loverajoel Can you tell me what is the next step please. Could I do modification ? thank.
@JakeRawr we need 5 shipits to merge this, I'll try merge this week
:shipit: 🐔
:shipit: 🎱
:shipit: 👍
:shipit:
:shipit:
Make easy loop on array
TL;DR;
Make a elegant loop on array
Username
Julien jamet: github