Created
August 17, 2012 11:05
-
-
Save streunerlein/3378008 to your computer and use it in GitHub Desktop.
Array.map() that works with undefined values in Array
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.ownMap = function(fn) { var a = new Array(this.length); for (var i = 0; i < this.length; i++) a[i] = fn(this[i]); return a; } | |
// t = new Array(4) | |
// > [undefined × 4] | |
// t.ownMap(function(d) { return "Q"; }) | |
// > ["Q", "Q", "Q", "Q"] | |
// t | |
// > [undefined × 4] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment