The idea I had behind the range method was not just to create, but was also
to modify.  By altering the index properties, you can create staggered
arrays and other such things.  I havn't figured out how I want to denote a
set yet, I just have ranges supported for now. 

 

Example:

http://mootools.net/shell/LrzTf/

 

Syntax: Array.Range(repeat, func)
Syntax: Array.Range([start, end], func);
Syntax: Array.Range([start, end, step], func);



Array.Range(5, function(index){ return new Element('div', {html:index}); });
[div, div, div, div, div, div]

 

Array.Range([3, 6],  function(index){ return new Element('div',
{html:index}); });

 [undefined, undefined, undefined, div, div, div, div]

 

Array.Range([3, 10, 2], function(index){ return new Element('div',
{html:index}); });
[undefined, undefined, undefined, div, undefined, div, undefined, div,
undefined, div]

 

staggered = Array.Range([2, 20, 2],  function(index){ return new
Element('div',  {html:index}); });
staggered = staggered.Range([1, 19, 2], function(index){ return new
Element('span', {html:index}); });

 [undefined, span, div, span, div, span, div, span, div, span, div, span,
div, span, div, span, div, span, div, span, div]

 

 

You could create tons of things with this logic, for instance a deck of
playing cards.

 

Cards = Array.Range([0, 51], function(index) {

     // Logic to determine card number, suit and value

});

 

This is how i'd like to denote a set, it's just not valid javascript:

 

Array.Range({3, 7, 56, 92, 104}, function(index) {

     // This will get an error

}

 

I could put quotes around it but that's ugly :-)

 

From: [email protected]
[mailto:[email protected]] On Behalf Of Fábio M. Costa
Sent: Wednesday, March 03, 2010 7:45 PM
To: [email protected]
Subject: Re: [Moo] Mootools Feature Suggestion

 

ive created a proof of concept:

http://mootools.net/shell/Y4Jpd/


--
Fábio Miranda Costa
Solucione Sistemas
Engenheiro de interfaces



2010/3/3 Fábio M. Costa <[email protected]>

Sorry the first example was incorrect:

Array.range(2); // returns [0,1]



--
Fábio Miranda Costa
Solucione Sistemas
Engenheiro de interfaces



On Wed, Mar 3, 2010 at 9:24 PM, Trevor Orr <[email protected]> wrote:

I could see the being useful once in a while, think it might be a good
addition to the more library.






On Wed, Mar 3, 2010 at 4:19 PM, hazlema <[email protected]> wrote:

In my opinion, it would be really cool if mootools could use a range
operator for numeric sets:

new Array.Range( [0, 10] );

would create an array with 11 empty elements

new Array.Range( [0, 10] , function() {
   return new Element('div');
});

would create an array with 11 elements with div in each spot

Consider this code segment:

Days = new Array().Range( [0, 31], function(index) {
                   ele = new Element('div', {class: 'weekdays'});
                   if ((index % 7 == 0) || (index % 7 == 6))
ele.removeClass('weekdays').setClass('weekends');
                  return ele;
          });
You got it, its a calendar

You could use it for existing arrays as well:

DaysArray.Range( [9, 11], function(index) {
             this.Hide();
});

Just a thought I had while I was building an app, what do you think?

 

 

 

Reply via email to