Last active
March 20, 2016 06:49
-
-
Save RSNara/45e15bc8747a26d18a6c to your computer and use it in GitHub Desktop.
Easily create an nth dimensional array. Useful for DP questions.
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 ArrayNDOf(factory) { | |
return function ArrayND(first, ...rest) { | |
return Array.apply(null, { length: first }).map(() => { | |
return rest.length == 0 ? factory() : ArrayND(...rest); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment