←
^
→
AJAX Tricks and Prototype
Enumerable
Mixin
methods for enumerations.
collect
to apply a function to all list members and return results in a list:
['Hitch', "Hiker's", 'Guide', 'To', 'The', 'Galaxy'].collect(
function(s) { return s.charAt(0).toUpperCase();}).join('')
$R(1,5).collect(function(n) {return n * n;})
Iterate over a list, with index:
['hello', 'world'].each(function(s, index) {alert(index + ': ' + s);})
Find something in a list:
['hello','world','this','is','nice'].find(function(s) {return s.length == 4;})
You can grep:
$R(1,30).grep(/[05]$/)
Find the max/min:
$R(1,10).max()
Partition a list into two:
$R(1, 10).partition(function(n) {
return 0 == n % 2;
})
Sort:
['hello', 'world', 'this', 'is', 'nice'].sortBy(function(s) { return s.length; })
José M. Vidal
.
13 of 16