Skip to content

Instantly share code, notes, and snippets.

@kirkegaard
Last active August 18, 2025 16:28
Show Gist options
  • Save kirkegaard/fb4bd56ecaf193fd2ab4b79d7a3a24f6 to your computer and use it in GitHub Desktop.
Save kirkegaard/fb4bd56ecaf193fd2ab4b79d7a3a24f6 to your computer and use it in GitHub Desktop.
@cassidoo mailing list question
function createLaundryItem() {
let count = 0;
const tasks = [
"soak",
"wash",
"rinse",
"spin",
"dry",
];
const next = () => {
if (count < tasks.length) {
return tasks[count++];
}
return "done";
}
return {
nextCycle: next,
}
};
let towel = createLaundryItem();
console.log(towel.nextCycle()); // "soak"
console.log(towel.nextCycle()); // "wash"
console.log(towel.nextCycle()); // "rinse"
console.log(towel.nextCycle()); // "spin"
console.log(towel.nextCycle()); // "dry"
console.log(towel.nextCycle()); // "done"
console.log(towel.nextCycle()); // "done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment