Skip to content

Instantly share code, notes, and snippets.

@jcreighton
Last active May 14, 2019 21:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcreighton/0ea233dd0391d57d866e78a6b538775c to your computer and use it in GitHub Desktop.
Save jcreighton/0ea233dd0391d57d866e78a6b538775c to your computer and use it in GitHub Desktop.
Irritable Iterator
function irritable() {
let step = 0;
return {
next: function() {
step++;
if (step === 1) {
return { value: '😠', done: false };
}
if (step === 2) {
return { value: '😡', done: false };
}
if (step === 3) {
return { value: '🤬', done: false };
}
return { value: undefined, done: true };
}
};
}
Array.prototype[Symbol.iterator] = irritable;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment