Skip to content

Instantly share code, notes, and snippets.

@QuadFlask
Created February 29, 2016 01:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save QuadFlask/2811b3c56823ea10e25d to your computer and use it in GitHub Desktop.
Save QuadFlask/2811b3c56823ea10e25d to your computer and use it in GitHub Desktop.
[CodeWras] xD-Arrays for dimmies
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