Related Setup: https://gist.github.com/hofmannsven/6814278
Related Pro Tips: https://ochronus.com/git-tips-from-the-trenches/
| // Problem 1 | |
| (() => { | |
| console.log('this is the start'); | |
| setTimeout(function cb() { | |
| console.log('this is a msg from call back'); | |
| }); | |
| console.log('this is just a message'); | |
| setTimeout(function cb1() { | |
| console.log('this is a msg from call back1'); | |
| }, 0); |
| // JS Hoisting | |
| function parent() { | |
| var hoisted = "I'm a variable"; | |
| function hoisted() { | |
| return "I'm a function"; | |
| } | |
| return hoisted(); | |
| } | |
| console.log(parent()); |
| // https://levelup.gitconnected.com/understand-javascript-promises-by-building-a-promise-from-scratch-84c0fd855720 | |
| // http://thecodebarbarian.com/write-your-own-node-js-promise-library-from-scratch.html | |
| class PromiseSimple { | |
| constructor(executionFunc) { | |
| this.chains = []; | |
| this.handleError = () => { console.log('err!'); }; | |
| this.onResolve = this.onResolve.bind(this); | |
| this.onReject = this.onReject.bind(this); | |
| executionFunc(this.onResolve, this.onReject); |
| /* | |
| * Difficulty: Easy | |
| * Create an event emitter that goes like this | |
| * emitter = new Emitter(); | |
| * | |
| * Allows you to subscribe to some event | |
| * emitter.subscribe('event1', callback1); | |
| * (you can have multiple callbacks to the same event) | |
| * emitter.subscribe('event1', callback2); | |
| * |
| class PromiseSimple { | |
| } | |
| fakeApiBackend = () => { | |
| const user = { | |
| username: 'John Doe', | |
| favoriteNumber: 42, | |
| profile: 'https://gitconnected.com/johndoe' | |
| }; |
Related Setup: https://gist.github.com/hofmannsven/6814278
Related Pro Tips: https://ochronus.com/git-tips-from-the-trenches/
| function GameOfLife(width,height) { | |
| this.width = width; | |
| this.height = height; | |
| this.nextState = []; | |
| } | |
| GameOfLife.prototype.createAndShowBoard = function () { | |
| // create <table> element | |
| var goltable = document.createElement("tbody"); | |
| var traverseDomAndCollectElements = function(matchFunc, startEl) { | |
| var resultSet = []; | |
| if (typeof startEl === "undefined") { | |
| startEl = document.body; | |
| } | |
| // if (matchFunc(startEl)) | |
| // resultSet.push(startEl); |
| def get_from_digg | |
| res = JSON.load(RestClient.get('http://digg.com/api/news/popular.json')) | |
| res["data"]["feed"].map do |story| | |
| s = {} | |
| tags = [] | |
| s[:title] = story["content"]["title"] | |
| story["content"]["tags"].map do |tag| | |
| tags << tag["display"] | |
| end | |
| s[:category] = tags.join(", ") |