I want to create an array of all possible combinations of three variables that can either be true or false (i.e. 8 possible combinations).
I am trying to create the cube in the top left corner at this image
So the output should be something like
points = [
// first square
{
id: '000',
truths: [false, false, false]
position: [0, 0]
},
{
id: '100',
truths: [true, false, false]
position: [5, 0]
},
{
id: '010',
truths: [false, true, false]
position: [0, 5]
},
{
id: '110',
truths: [true, true, false]
position: [5, 5]
},
// second square
{
id: '001',
truths: [false, false, true]
position: [2.5, 2.5]
},
{
id: '101',
truths: [true, false, true]
position: [7.5, 2.5]
},
{
id: '011',
truths: [false, true, true]
position: [2.5, 7.5]
},
{
id: '111',
truths: [true, true, true]
position: [7.5, 7.5]
},
];
lines = [
{ from: '000', to: '100' },
{ from: '000', to: '010' },
{ from: '000', to: '001' },
{ from: '100', to: '101' },
{ from: '100', to: '110' },
{ from: '001', to: '101' },
{ from: '001', to: '011' },
{ from: '101', to: '001' },
{ from: '101', to: '111' },
...
]
I don't know how to go through all possible truth values and create these points.
One approach could be to use a for loop
for (var i=0; i<Math.pow(2, 3); i++) {
...
}
but it doesn't help me assigning the possible truth values.