Last active
January 10, 2016 15:51
-
-
Save alexnm/2d428019135f747bbf9c to your computer and use it in GitHub Desktop.
Exemplifying ES2015 sytanx
This file contains 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
// Basic syntax examples | |
var add = ( a, b ) => a + b; // function( a, b ) { return a + b; } | |
var increment = a => a + 1; // function( a ) { return a + 1; } | |
var random = ( ) => Math.random( ) // function( ) { return Math.random( ); } | |
// Functional programming unleashed | |
var array = [ 'alice', 'bob', 'charles', 'dan', 'eugene', 'felicity' ]; | |
var longNames = array.filter( name => name.length > 3 ); | |
var longNamesIndexes = longNames.map( ( name, index ) => index ); | |
var sumOfIndexes = longNamesIndexes.reduce( add ); | |
// One liner mindfuck | |
var sumOfIndexes = array.filter( n => n.length > 3 ) | |
.map( ( n, i ) => i ) | |
.reduce( ( a, b ) => a + b ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment