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
var square = function () { | |
return arguments.map(function(arg) { | |
return arg * arg; | |
}); | |
}; | |
square(1, 2, 3, 4, 5); // => "TypeError: arguments.map is not a function |
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
var square = function() { | |
var args = Array.prototype.slice.call(arguments); // convert arguments to array. | |
return args.map(function(arg) { | |
return arg * arg; | |
}); | |
}; | |
square(1, 2, 3, 4, 5); // => [1, 4, 9, 16, 25] |
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
var square = function(...args) { | |
return args.map(function(arg) { | |
return arg * arg; | |
}); | |
}; | |
square(1, 2, 3, 4, 5); // => [1, 4, 9, 16, 25] |
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
const square = (...args) => args.map((arg) => arg * arg); | |
square(1, 2, 3, 4, 5); // => [1, 4, 9, 16, 25] |
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
var sum = function () { | |
var result = 0; | |
arguments.forEach(function(number) { | |
result = result + number; | |
}); | |
return result; | |
}; |
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
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; | |
}; |
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
var stateManger = function () { | |
var active = false; | |
var setState = function(state) { | |
active = state; | |
}; | |
return { | |
toggle: function () { | |
return setState(!active); | |
}, |
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
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 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
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 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
function functionFactory({ type, ...rest }) { | |
switch(type) { | |
case 'hi': | |
return hello(rest); | |
case 'bye': | |
return goodbye(rest); | |
} | |
}; | |
function hello({ name }) { |