Created
April 12, 2013 14:30
-
-
Save hendriklammers/5372413 to your computer and use it in GitHub Desktop.
Javascript - createArray
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
/** | |
* Creates a multidimensional Array | |
* @param {Number} length Number of dimensions the new Array should have | |
* @return {Array} The newly created Array | |
*/ | |
function createArray(length) { | |
var arr = new Array(length || 0), | |
i = length; | |
if (arguments.length > 1) { | |
var args = Array.prototype.slice.call(arguments, 1); | |
while(i--) arr[length-1 - i] = createArray.apply(this, args); | |
} | |
return arr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment