Skip to content

Commit d3e6868

Browse files
committed
Enhance renderObjectSet function to support dynamic cup rendering based on filled and empty counts. Introduce logic for reducing fractions and randomizing filled cup positions when applicable.
1 parent bd35774 commit d3e6868

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

fractions-practice.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,20 @@ function renderCup(isEmpty) {
170170
}
171171

172172
function renderObjectSet(total, emptyCount) {
173-
const cups = [];
173+
const filledCount = total - emptyCount;
174+
const fractionReduces = gcd(emptyCount, total) > 1;
175+
176+
if (fractionReduces && filledCount > 0 && emptyCount > 0) {
177+
const filledStart = randomInt(0, total - filledCount);
178+
const cups = [];
179+
for (let index = 0; index < total; index += 1) {
180+
const isFilled = index >= filledStart && index < filledStart + filledCount;
181+
cups.push(renderCup(!isFilled));
182+
}
183+
return `<div class="object-set">${cups.join('')}</div>`;
184+
}
174185

186+
const cups = [];
175187
for (let index = 0; index < total; index += 1) {
176188
cups.push(renderCup(index < emptyCount));
177189
}

0 commit comments

Comments
 (0)