Created
April 29, 2013 04:21
-
-
Save PatrickJS/5479687 to your computer and use it in GitHub Desktop.
add .last() to all Arrays
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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