Created
June 22, 2014 14:34
-
-
Save thomasjo/1c102ac17864eba42b47 to your computer and use it in GitHub Desktop.
JavaScript's Array.reduce is silly...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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