|
This post originated from an RSS feed registered with Ruby Buzz
by Red Handed.
|
Original Post: The Javascript-Ruby Connection Slims
Feed Title: RedHanded
Feed URL: http://redhanded.hobix.com/index.xml
Feed Description: sneaking Ruby through the system
|
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Red Handed
Latest Posts From RedHanded
|
|
Yeah, Ruby and Javascript have a close proximity—flgr once gave us proof. MenTaL spotted a list of additions to Javascript arrays, which reeks of the Ruby Way.
Of special note is the addition of forEach, but just look how valuable the Ruby equivalents of these methods have become to us:
| JS |
Ruby |
indexOf |
index |
lastIndexOf |
rindex |
some |
any? |
every |
all? |
filter |
find_all |
forEach |
each |
map |
map |
Interesting. I’m reading here and each of the iterators sends three parameters to the “block”. The value, the current index and the array itself.
var aNumbers = [4, 2, 6, 9];
var aTimesTwoNumbers = aNumbers.map(function (v, i, ary) {
return v * 2;
});
It’s that index value. We’ve never known where to put it. I believe in Javascript you can safely omit parameters you’re not using. (via webref.)
Read: The Javascript-Ruby Connection Slims