Skip to content

Instantly share code, notes, and snippets.

@bignimbus
Last active January 11, 2016 19:10
Show Gist options
  • Save bignimbus/75a09cf5b4db4f7d289e to your computer and use it in GitHub Desktop.
Save bignimbus/75a09cf5b4db4f7d289e to your computer and use it in GitHub Desktop.
Representing a multidimensional plane in javascript
const makeCube = (d = 0) => {
let arr = new Array(SIZE);
if (d === DIMENSIONS) {
return arr.fill(0);
}
return arr.fill(makeCube(d + 1));
};
const cube = makeCube();
const boundFactory = (end) => {
return function* (n = 0) {
for (; n <= end; n++) {
yield n;
}
};
};
const fieldFactory = () => boundFactory(Math.pow(SIZE, DIMENSIONS));
const set = function * () {
let field = fieldFactory();
for (let f of field()) {
yield [f]; //.toString(SIZE).split('').map((num) => parseInt(num, SIZE));
}
}
let coords = {};
for (let n of set()) {
coords[n] = 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment