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 myNums = [1, 2, 3, 4, 5]; | |
| function doubleNum(num) { | |
| return num * 2; | |
| } | |
| // Built-in Array.prototype.map function, using anonymous function argument | |
| var doubledNums = myNums.map(function(num) { | |
| return num * 2; | |
| }); |
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 applicator(fn, val) { | |
| return function() { | |
| fn(val); | |
| }; | |
| } | |
| function speak(string) { | |
| console.log(string); | |
| } |
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 speak(string) { | |
| console.log(string); | |
| } | |
| var delayedFunction = function(fn) { | |
| return function(val, delay) { | |
| setTimeout(function() { | |
| fn(val); | |
| }, delay); | |
| }; |
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 isPalindrome(str) { | |
| var reverse = str.split("").reverse().join(""); | |
| return str === reverse; | |
| } | |
| function getCharCounts(chars) { | |
| var charCounts = {}; | |
| for (var i = 0, charLen = chars.length; i < charLen; i += 1) { | |
| if (charCounts[chars[i]]) { | |
| charCounts[chars[i]] += 1; |
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 prices = [400, 80, 375, 870]; | |
| // 1 | |
| for (var i = 0; i < prices.length; i += 1) { | |
| console.log(prices[i]); | |
| } | |
| // logs 400, 80, 375, 870 | |
| // 2 | |
| for (var k in prices) { |
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 products = { | |
| "widget": 400, | |
| "gear": 80, | |
| "crank": 375, | |
| "lever": 870, | |
| }; | |
| // 1 | |
| var productKeys = Object.keys(products); | |
| for (var i = 0; i < productKeys.length; i += 1) { |
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 prices = [400, 80, 375, 870]; | |
| var products = { | |
| "widget": 400, | |
| "gear": 80, | |
| "crank": 375, | |
| "lever": 870, | |
| }; | |
| var pricesDescriptors = Object.getOwnPropertyDescriptors(prices); |
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 prices = [400, 80, 375, 870]; | |
| Object.defineProperty(prices, 1, { enumerable: false }); | |
| for (var k in prices) { | |
| console.log(prices[k]); | |
| } | |
| // logs 400, 375, 870 ... the 80 is missing! |
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 products = { | |
| "widget": 400, | |
| "gear": 80, | |
| "crank": 375, | |
| "lever": 870, | |
| }; | |
| Object.defineProperty(products, "gear", { enumerable: false }); | |
| // 1 |
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 products = { | |
| "widget": 400, | |
| "gear": 80, | |
| "crank": 375, | |
| "lever": 870, | |
| }; | |
| var otherProducts = Object.create(products); | |
| otherProducts["wheel"] = 210; |