Javascript Function Learning

https://www.quora.com/What-are-JavaScript-basics-that-every-beginner-should-learn/answer/Sean-May-6

Sample MapReduce

[ { x: 22 }, { x: 42 }, {x: 21} , {x: 45}].map( el => el.x ) .reduce((max, current) => Math.max(max, current), -Infinity );

The functions that you return will remember whatever was passed into / created in their parents / parents’ parents, from the time of their creation.

function hello (x) { return function () { return "hello,"+x; }; }

var world = hello('World'), Universe = hello("universe");

world(); universe();

function remember (x) { return function recall () { return x; }; }

var x = 12; var remember42 = remember(42); var remember18 = remember(18); var remember33 = remember(33); x = 9; remember42(); // 42 remember33(); // 33 x = 88; remember18(); // 18

Working with Collection

var people = [ { name: "Bob", gender: "male" }, { name: "Doug", gender: "male" }, { name: "Sarah", gender: "female" }, { name: "Susan", gender: "female" }, { name: "Hannah", gender: "female" } ];

var numberOfLettersInGirlsNames = people .filter(person => person.gender === "female") .map(person => person.name.length) .reduce((total, x) => total + x, 0);

numberOfLettersInGirlsNames; // 16