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 text = "This string contains the name Derrik"; | |
| var myName = "Derrik"; | |
| var hits = []; | |
| for(var i = 0; i < text.length; i++) { | |
| if (text[i] === 'D') { | |
| for(var j = i; i > (myName.length + i); j++) { | |
| hits.push(text[j]); |
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
Show hidden characters
| { | |
| "ignored_packages": | |
| [ | |
| "Vintage" | |
| ], | |
| //theme stuff | |
| "color_scheme": "Packages/User/SublimeLinter/Oceanic Next (SL).tmTheme", | |
| "theme": "Broceanic.sublime-theme", | |
| //general |
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
| //the most basic async cb | |
| sleep = function(ms) { | |
| let promise = new Promise(function(resolve, reject) { | |
| setTimeout(function() { | |
| resolve("the result"); | |
| }, ms); | |
| }); | |
| return promise; | |
| }; |
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
| //the most basic async cb in es5 | |
| var sleep = function(ms) { | |
| var promise = new Promise(function(resolve, reject) { | |
| setTimeout(function() { | |
| resolve("the result"); | |
| }, ms); | |
| }); | |
| return promise; |
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
| let arr = [4, 9, 14]; | |
| // the old way | |
| let newArr = arr.map(function (value) { | |
| return value + 1; | |
| }); | |
| // the new way - ES2015 (3 examples of the same function, each better than the one before it) | |
| let newArr = arr.map( (value) => { return value +1; }); | |
| arr.map( value => { return value + 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
| function isNegativeZero(x) { | |
| return x === 0 && (1/x < 0); | |
| } |
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 heap = {}; | |
| var stack = []; | |
| var callFunction = function (nameFunc, args, lineNumber) { | |
| var func = heap[nameFunc]; | |
| var stackFrame = { | |
| funcy: func, | |
| name: nameFunc, | |
| args: args, | |
| env: {}, |
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
| // create a function called forEach that iterates over all items in a list and calls a callback for each item | |
| // note: this concept is attached to the array object automatically. this is just to illustrate what is happening under the hood | |
| items = ['one', 'two', 'three']; | |
| //iterator function 1 | |
| forEach = function (array, func) { //func = callback function that is passed in (the iterator!) | |
| for (var i = 0; i < array.length; i++) { | |
| func(array[i], i); //item in array, and index item in array | |
| } |
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
| whenDone = function () { | |
| console.log ("done") | |
| }; | |
| doWork = function(callback) { | |
| //do some work | |
| setTimeout(callback, 3000); //put the call back on the event loop by 3 seconds (during this time, other work is being done) | |
| }; |
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
| /* | |
| the synchronous callback: | |
| create a function that can be called at a later time whenever the | |
| higher order function (the function that were passing this function into -- aka: the function doing the calling) | |
| is ready to call/invoke this function. Read this a few times and it will eventually make sense :) | |
| */ | |
| whenDone = function () { | |
| console.log ("done") | |
| }; |