Skip to content

Instantly share code, notes, and snippets.

@JamesKyburz
Created August 25, 2011 17:29
Show Gist options
  • Save JamesKyburz/1171220 to your computer and use it in GitHub Desktop.
Save JamesKyburz/1171220 to your computer and use it in GitHub Desktop.
cycle.js
var cycle = function() {
var i = 1;
return function(first, second) {
if (first === 'reset') {
i = 1;
return;
}
var value = [first, second][i = 1 - i];
return value;
};
}();
cycle('odd', 'even'); //# => odd
cycle('odd', 'even'); //# => even
cycle('odd', 'even'); //# => odd
cycle('reset');
cycle('odd', 'even'); //# => odd
cycle('odd', 'even'); //# => even
cycle('odd', 'even'); //# => odd
cycle('odd', 'even'); //# => even
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment