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 wrapValue(n) { | |
| var localVariable = n; | |
| return function() { return localVariable; }; | |
| } | |
| var wrap1 = wrapValue(1); | |
| var wrap2 = wrapValue(2); | |
| console.log(wrap1()); | |
| // 1 | |
| console.log(wrap2()); |
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 multiplier(factor) { | |
| return function(number) { | |
| return number * factor; | |
| }; | |
| } | |
| var twice = multiplier(2); | |
| console.log(twice(5)); | |
| // 10 |
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 greaterThan(n) { | |
| return function(m) { return m > n; }; | |
| } | |
| var greaterThan10 = greaterThan(10); | |
| console.log(greaterThan10(11)); | |
| // true |
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 greaterThan(n) { | |
| return function(m) { return m > n; }; | |
| } | |
| var greaterThan10 = greaterThan(10)(20); | |
| console.log(greaterThan10); | |
| // true |
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 arr = [10,38,4,8,6,60,3]; | |
| console.log(arr.reduce(function(min, cur) { | |
| if(cur < min ) return cur; | |
| else return min | |
| })); | |
| // 3 |
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
| Programas são pensamentos "cristalizados". Algumas vezes, esses pensamentos são confusos e | |
| erros podem ser inseridos quando convertemos pensamentos em código, resultando em um programa com falhas. |
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 dayName = function() { | |
| var names = ["Sunday", "Monday", "Tuesday", "Wednesday", | |
| "Thursday", "Friday", "Saturday"]; | |
| return function(number) { | |
| return names[number]; | |
| }; | |
| }(); | |
| console.log(dayName(3)); | |
| // → Wednesday |
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() { | |
| function square(x) { return x * x; } | |
| var hundred = 100; | |
| console.log(square(hundred)); | |
| })(); | |
| // 10000 |
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 weekDay = function() { | |
| var names = ["Sunday", "Monday", "Tuesday", "Wednesday", | |
| "Thursday", "Friday", "Saturday"]; | |
| return { | |
| name: function(number) { return names[number]; }, | |
| number: function(name) { return names.indexOf(name); } | |
| }; | |
| }(); | |
| console.log(weekDay.name(weekDay.number("Sunday"))); |
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(exports) { | |
| var names = ["Sunday", "Monday", "Tuesday", "Wednesday", | |
| "Thursday", "Friday", "Saturday"]; | |
| exports.name = function(number) { | |
| return names[number]; | |
| }; | |
| exports.number = function(name) { | |
| return names.indexOf(name); | |
| }; |
OlderNewer