Last active
January 11, 2016 19:10
-
-
Save bignimbus/75a09cf5b4db4f7d289e to your computer and use it in GitHub Desktop.
Representing a multidimensional plane in javascript
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
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(); |
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
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