Skip to content

Instantly share code, notes, and snippets.

@PatrickJS
Created April 29, 2013 04:21
Show Gist options
  • Save PatrickJS/5479687 to your computer and use it in GitHub Desktop.
Save PatrickJS/5479687 to your computer and use it in GitHub Desktop.
add .last() to all Arrays
Array.prototype.last = function(n) {
if (n === undefined) {
return this[this.length-1];
}
var answers = [];
for(var i = this.length-1; i>this.length-n-1;i-=1){
answers.unshift(this[i]);
}
return answers;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment