function everyOther(start, end, increment) {
        var n;
        var rv = [];
        for (n = start; n <= end; n += increment) {
            rv[rv.length] = n;
        }
        return rv;
    }



Just a mod to make it better to be able to change it to 3's, 4's, 5's


;)




Alex Mcauley
http://www.thevacancymarket.com
----- Original Message ----- 
From: "T.J. Crowder" <t...@crowdersoftware.com>
To: "Prototype & script.aculo.us" <prototype-scriptaculous@googlegroups.com>
Sent: Friday, September 25, 2009 8:29 AM
Subject: [Proto-Scripty] Re: Range utility increment



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 <tokyot...@gmail.com> 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 prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to