Skip to content

Instantly share code, notes, and snippets.

@ben-bradley
Last active August 29, 2015 14:00
Show Gist options
  • Save ben-bradley/11408731 to your computer and use it in GitHub Desktop.
Save ben-bradley/11408731 to your computer and use it in GitHub Desktop.
awesome technique for dealing with a counter at zero
[ 0, 1, 2, 3, 4, 5 ].forEach(function(y) { var z = --y || 'wut!?'; console.log(z); })
/* output:
-1
"wut!?"
1
2
3
4
*/
/* "wut!?" can be anything (function!) */
/* picked it up from https://github.com/learnboost/kue#parallel-processing-with-cluster */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment