Created
December 11, 2020 09:00
-
-
Save tpps88206/0ba4908268de74c22cf7156cc333b13e to your computer and use it in GitHub Desktop.
在 JavaScript 中實作 map 函數
This file contains hidden or 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.map = function(callback) { | |
| var result = []; | |
| this.forEach(function(element, index) { | |
| result.push(callback(element, index)); | |
| }) | |
| return result; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment