Skip to content

Instantly share code, notes, and snippets.

@Announcement
Created February 29, 2020 13:11
Show Gist options
  • Save Announcement/8f354b7da99b5a2d96dd3236de780f9a to your computer and use it in GitHub Desktop.
Save Announcement/8f354b7da99b5a2d96dd3236de780f9a to your computer and use it in GitHub Desktop.
algorithm judgement/advice
function* createObjectThrough0 (object) {
const entries = Object.entries(object);
const objects0 = [];
const objects1 = [];
for (let currentEntryIndex = 0,
maximumEntryIndex = entries.length;
currentEntryIndex < maximumEntryIndex;
currentEntryIndex++)
{
const [currentVariableName, currentVariableValue] = entries[currentEntryIndex];
objects0.splice(0, objects0.length, ...objects1.splice(0));
for (let currentValue = 0,
maximumValue = currentVariableValue;
currentValue <= maximumValue;
currentValue++)
{
const currentVariable = { [currentVariableName]: maximumValue - currentValue };
if (currentEntryIndex === 0)
{
objects1.push(currentVariable)
}
if (maximumEntryIndex - currentEntryIndex - 1 === 0)
{
for (let currentObject of objects0) {
objects1.push({ ...currentObject, ...currentVariable });
}
}
}
}
objects0.splice(0, objects0.length, ...objects1.splice(0));
yield* objects0;
}
// output:
// { x: 1, y: 1 } { x: 0, y: 1 } { x: 1, y: 0 } { x: 0, y: 0 }
// desired output:
// { x: 1: y: 1 } { x: 1, y: 0 } { x: 0, y: 1 } { x: 0, y: 0 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment