Skip to content

Instantly share code, notes, and snippets.

@jslnriot
Created April 8, 2016 01:01
Show Gist options
  • Save jslnriot/03e9089e684677c4fddf3587a4938884 to your computer and use it in GitHub Desktop.
Save jslnriot/03e9089e684677c4fddf3587a4938884 to your computer and use it in GitHub Desktop.
create a function that gets the max number in an array
Array.prototype.max = function(){
return this.reduce(function(prev,curr) {
return Math.max(prev,curr);
});
}
arr = [1,2,4,3,6,3,7,8,2];
console.log(arr.max());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment