Created
February 6, 2019 16:32
-
-
Save dlucidone/0e67cebdbb830059e48b2b0dffc382d5 to your computer and use it in GitHub Desktop.
Apply Implementation
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
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