Skip to content

Instantly share code, notes, and snippets.

@thomasjo
Created June 22, 2014 14:34
Show Gist options
  • Select an option

  • Save thomasjo/1c102ac17864eba42b47 to your computer and use it in GitHub Desktop.

Select an option

Save thomasjo/1c102ac17864eba42b47 to your computer and use it in GitHub Desktop.
JavaScript's Array.reduce is silly...
segments = "text.foo.bar.quux".split(".");
segments.reduce(function(aggregate, current, index) {
console.log(index);
});
// Result:
// 1
// 2
// 3
segments.reduce(function(aggregate, current, index) {
console.log(index);
}, null);
// Result:
// 0
// 1
// 2
// 3
// (╯°□°)╯︵ ┻━┻ ︵ ╯(°□° ╯)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment