Skip to content

Instantly share code, notes, and snippets.

@layonthebeech
Created August 18, 2016 21:59
Show Gist options
  • Save layonthebeech/8a79e788df6a7f3bf092552b48b87872 to your computer and use it in GitHub Desktop.
Save layonthebeech/8a79e788df6a7f3bf092552b48b87872 to your computer and use it in GitHub Desktop.
Array.prototype.int = function (){
return this.filter(function (x) { return typeof x == 'number' && x == ~~x });
}
Array.prototype.even = function(){
return this.int().filter(function (x) { return ~x & 1 });
}
Array.prototype.odd = function(){
return this.int().filter(function (x) { return x & 1 });
}
Array.prototype.under = function(x){
return this.int().filter(function (y) { return y < x });
}
Array.prototype.over = function(x){
return this.int().filter(function (y) { return y > x });
}
Array.prototype.inRange = function(min,max){
return this.int().filter(function (x) { return x >= min && x <= max });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment