Last active
November 13, 2019 10:13
-
-
Save hjzheng/94c2a6ad25fc5a002a6d328a7f7ad90c to your computer and use it in GitHub Desktop.
生成二维数组
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
function genArray(rows, cols, something) { | |
// BAD! Rows are copied by reference | |
// return new Array(rows).fill(new Array(cols).fill(something)) | |
// good way | |
Array.from(Array(rows), () => new Array(cols).fill(something)) | |
// more inefficient 12% | |
// return new Array(rows).fill(null).map(() => Array(cols).fill(something)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment