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
const xs = [1, 2, 3, 4, 5]; | |
const x = xs.pop(); //=> 5 |
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
const xs = [1, 2, 3, 4, 5]; | |
const x = xs[xs.length - 1]; //=> 5 |
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
const xs = [1, 2, 3, 4, 5]; | |
const [ x ] = xs.slice(-1); //=> 5 |
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
const generator = (x, y = x) => { | |
return {x: `_${x}`, y}; | |
}; |
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
var xs = { | |
template: [ | |
{template: 'one', dest: 'two'}, | |
{template: 'one', dest: 'two'} | |
], | |
copy: [ | |
{template: 'one', dest: 'two'}, | |
{template: 'one', dest: 'two'} | |
] | |
}; |
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
function functionFactory({ type, ...rest }) { | |
switch(type) { | |
case 'hi': | |
return hello(rest); | |
case 'bye': | |
return goodbye(rest); | |
} | |
}; | |
function hello({ name }) { |
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
shh reduce | |
such reduce much fn xs accum index | |
rly index === xs.length -1 | |
wow accum | |
wow reduce(fn, xs, fn(accum, xs[index + 1]), index + 1) | |
shh map | |
such map much fn xs | |
such _map much previous current |
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
var stateManger = function () { | |
var active = false; | |
var setState = function(state) { | |
active = state; | |
}; | |
return { | |
toggle : setState.bind(this, !active), | |
setActive : setState.bind(this, true), | |
setInactive : setState.bind(this, false) |
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
var stateManger = function () { | |
var active = false; | |
var setState = function(state) { | |
active = state; | |
}; | |
return { | |
toggle: function () { | |
return setState(!active); | |
}, |
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
var sum = function () { | |
var result = 0; | |
var args = Array.prototype.slice.call(arguments); // convert arguments into array | |
args.forEach(function(number) { | |
result = result + number; | |
}); | |
return result; | |
}; |