Is there any way by which I can skip a particular number of objects and take certain objects from an organ in javascript Can i
Basically I see that this pattern is.
Say I have an array of 8 objects.
First loop:
Second loop:
Return Object array on objects in index 4 to 7 To
Third loop :
To return to the beginning so that the object is returned again from 0 to 3.
Ad Infiniti .....
I would love to see a Java based solution if possible, but I am also opening all to apply raw javascript because I Curious to learn.
Cheers.
Something like this (plain javascript, no need for jQuery;)): < Pre> var iterator = function (a, n) {var current = 0, l = a.length; Return function () {end = current + n; Var part = a.slice (current, end); Current = end & lt; L? Intra; Share of refund; }; };
Then you can call it:
var next = iterator (arr, 3); the upcoming(); // gives the next three to the next (); // gives the next three // etc.
This is the form, the last move can return the lesser element. You can also expand it and accept the function a variable step and a different initial parameter.
If you want to wrap around, as if only two elements are left, then to get the element from the beginning it becomes a little more sophisticated;)
Update: Wrap something like this:
var iterator = function (a, n) {var current = 0, l = a.length; Return function () {end = current + n; Var part = a.slice (current, end); If (End & G; L) {end = end% l; Part = part.concat (a.slice (0, end)); } Current = end; Share of refund; }; };
Comments
Post a Comment