dominiek (owner)

Forks

Revisions

gist: 204843 Download_button fork
public
Public Clone URL: git://gist.github.com/204843.git
Embed All Files: show embed
JavaScript #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// For all you Rubyists out there, jQuery has a couple "hidden" methods
// for working with arrays that work and are named just like Ruby, "grep" and "map":
 
foo = [1, 2, 3, 4, 5]
 
/*
Ruby way:
foo.grep do |value|
value > 2 && value < 5
end
*/
 
// jQuery way:
$.grep(foo, function(value, index){
  return value > 2 && value < 5;
});
// -> [3, 4]
 
/*
Ruby way:
foo.map do |value|
value * 2
end
*/
 
// jQuery way:
$.map(foo, function(value, index){
  return value * 2;
});
// -> [2, 4, 6, 8, 10]
 
 
// This jQuery tip has been brought to you by Paul Bakaus in the POOL.