Skip to content

Commit

Permalink
expose $.grep() as an interface to Array.filter
Browse files Browse the repository at this point in the history
  • Loading branch information
mislav committed Oct 3, 2012
1 parent ee9cda0 commit e92afc9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/zepto.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,10 @@ var Zepto = (function() {
return elements
}

$.grep = function(elements, callback){
return filter.call(elements, callback)
}

if (window.JSON) $.parseJSON = JSON.parse

// Define methods that will be available on all
Expand Down
6 changes: 6 additions & 0 deletions test/zepto.html
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,12 @@ <h1>Zepto DOM unit tests</h1>
t.assertEqual('name=banana,taste=sweet', results.sort().join(','))
},

testDollarGrep: function(t){
var fruits = ['apples', 'oranges', 'pineapple', 'peach']
var result = $.grep(fruits, function(name){ return /apple/.test(name) })
t.assertEqualCollection(['apples', 'pineapple'], result)
},

testDollarEach: function(t){
var array = ['a','b','c'], object = { a: 1, b: 2, c: 3 }, result

Expand Down

0 comments on commit e92afc9

Please sign in to comment.