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
| [ | |
| { | |
| "title": "Tribonacci Sequence", | |
| "link": "https://www.codewars.com/kata/556deca17c58da83c00002db", | |
| "date": "2019-06-11T12:39:57.923Z" | |
| }, | |
| { | |
| "title": "Playing with digits", | |
| "link": "https://www.codewars.com/kata/5552101f47fc5178b1000050", | |
| "date": "2019-06-12T12:39:57.923Z" |
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
| // first async example | |
| function logMessage2 () { | |
| console.log('Message 2') | |
| } | |
| console.log('Message 1') | |
| setTimeout(logMessage2, 1000) | |
| console.log('Message 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
| // blocking code example | |
| function blockingCode() { | |
| const startTime = new Date().getSeconds() | |
| // delay this function for 250 ms | |
| setTimeout(function() { | |
| const calledAt = new Date().getSeconds() | |
| const diff = calledAt - startTime | |
| // logs how long it took to call this 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
| function defer () { | |
| setTimeout(() => console.log('timeout with 0 delay!'), 0) | |
| console.log('after timeout') | |
| console.log('last log') | |
| } | |
| defer() |
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
| // Memoization Example | |
| // takes in a function to create a memoized version of | |
| const memoize = (func) => { | |
| // cache object | |
| // keys are the arguments, values are results | |
| const cache = {} | |
| // returns a new function | |
| // it remembers the cache object & func (closure) |
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
| // just logs the value of `this` to the console | |
| function logThis() { | |
| console.log('this =', this) | |
| } | |
| // DEFAULT BINDING | |
| // undefined in strict mode | |
| // global object in non-strict | |
| logThis() |
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
| console.log(this) // Global/Window |
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 logThis() { | |
| console.log('this =', this) | |
| } | |
| // named objThree just because there are more objects | |
| // in the future examples | |
| const objThree = { | |
| name: 'Object Three', | |
| logThisMethod: logThis | |
| } |
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
| 'use strict' | |
| function logThis() { | |
| console.log('this =', this) | |
| } | |
| // same example as earlier | |
| // default binding, `this` becomes undefined | |
| logThis() | |
| // global in NodeJS, window in browsers |
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
| //// BASE CODE //// | |
| 'use strict' | |
| const objOne = { | |
| name: 'Object One' | |
| } | |
| const objTwo = { | |
| name: 'Object Two' | |
| } | |
| function logThis() { | |
| console.log('this =', this) |