Created
February 29, 2016 01:37
-
-
Save QuadFlask/2811b3c56823ea10e25d to your computer and use it in GitHub Desktop.
[CodeWras] xD-Arrays for dimmies
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
http://www.codewars.com/kata/5402724fd39b43c075000116/train/javascript | |
```javascript | |
function fill(n, x) { | |
var a = []; | |
for(var i=0;i<n;i++) { | |
if (typeof x === 'function') a[i] = x(); | |
else if(x instanceof Array) a[i] = x.slice(0); | |
else a[i] = x; | |
} | |
return a; | |
} | |
function dim(...a) { | |
console.log(a) | |
if (a.length == 2) return fill(a[0], a[1]); | |
else if (a.length == 3) return fill(a[0], fill(a[1], a[2])); | |
else if (a.length > 3) return fill(a[0], dim.apply(null, a.slice(1))); | |
else return ''; | |
} | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment