Created
February 29, 2020 13:11
-
-
Save Announcement/8f354b7da99b5a2d96dd3236de780f9a to your computer and use it in GitHub Desktop.
algorithm judgement/advice
This file contains 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
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