Skip to content

Instantly share code, notes, and snippets.

@no6v
Created January 26, 2011 03:37
Show Gist options
  • Save no6v/796181 to your computer and use it in GitHub Desktop.
Save no6v/796181 to your computer and use it in GitHub Desktop.
diff --git a/public/javascripts/prototype.js b/public/javascripts/prototype.js
index dfe8ab4..bd16ae9 100644
--- a/public/javascripts/prototype.js
+++ b/public/javascripts/prototype.js
@@ -644,6 +644,20 @@ var Enumerable = {
return results;
},
+ count: function() {
+ var item = arguments[0];
+ switch (typeof item) {
+ case 'undefined': return this.length;
+ case 'function': return this.select(item).length;
+ default:
+ var c = 0;
+ this.each(function(value, index){
+ if (value == item) c++;
+ });
+ return c;
+ }
+ },
+
detect: function(iterator, context) {
var result;
this.each(function(value, index) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment