Hi,
> I'm looking for a way to specify that I want to increment by any
> value. Let's say count up by 2's: [2,4,6,8,10]. How do you do this?
ObjectRange itself is for ranges of consecutive values, but you can
get an array of such values by applying Enumerable#collect to a range:
var twos;
twos = $R(1, 5).collect(function(x) { return x * 2; });
...although frankly I'd probably go with a straight loop like Alex did
(although a slightly different one):
function everyOther(start, end) {
var n;
var rv = [];
for (n = start; n <= end; n += 2) {
rv[rv.length] = n;
}
return rv;
}
FWIW,
--
T.J. Crowder
tj / crowder software / com
www.crowdersoftware.com
On Sep 24, 11:15 pm, JoJo <[email protected]> wrote:
> http://www.prototypejs.org/api/utility/dollar-r
>
> From the documentation of the Range utility, it seems like it can only
> increment by 1's. For example, $A($R(1,10,true)) gives you:
> [1,2,3,4,5,6,7,8,9,10].
>
> I'm looking for a way to specify that I want to increment by any
> value. Let's say count up by 2's: [2,4,6,8,10]. How do you do this?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Prototype & script.aculo.us" 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/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---