Skip to content

Instantly share code, notes, and snippets.

@dlucidone
Created February 6, 2019 16:32
Show Gist options
  • Save dlucidone/0e67cebdbb830059e48b2b0dffc382d5 to your computer and use it in GitHub Desktop.
Save dlucidone/0e67cebdbb830059e48b2b0dffc382d5 to your computer and use it in GitHub Desktop.
Apply Implementation
Function.prototype.myApply = function(){
if(arguments[0]==null||arguments[0]==this){
return this.bind(...arguments[1])();
}
else{
return this.bind(...arguments[0])();
}
}
var numbers = [5, 6, 2, 3, 7];
var max = Math.max.myApply(null, numbers);
console.log(max);
// expected output: 7
var min = Math.min.myApply(numbers);
console.log(min);
// expected output: 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment