View 0_reuse_code.js
This file contains 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 Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
View string-replace-all.js
This file contains 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
String.prototype.replaceAll = function(search, replacement) { | |
var target = this; | |
return target.split(search).join(replacement); | |
}; |
View object-length.js
This file contains 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
Object.keys(myArray).length |
View index-of-object.js
This file contains 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 indexOfStevie = myArray.findIndex(i => i.hello === "stevie"); |
View mongo-find-in.js
This file contains 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
PersonModel.find({ favouriteFoods: { "$in" : ["sushi"]} }, ...); |
View array-map.js
This file contains 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 result = objArray.map(function(a) {return a.foo;}); |
View delay-loop.js
This file contains 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 myLoop (i) { | |
setTimeout(function () { | |
alert('hello'); // your code here | |
if (--i) myLoop(i); // decrement i and call myLoop again if i > 0 | |
}, 3000) | |
})(10); // pass the number of iterations as an argument |
View unhandled-promise-rejection.js
This file contains 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 myfunc = PTest(); | |
myfunc.then(function () { | |
console.log("Promise Resolved"); | |
}).catch(function () { | |
console.log("Promise Rejected"); | |
}); |
View random-bool.js
This file contains 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 random_boolean = Math.random() >= 0.5; |
View numbers-to-words.js
This file contains 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 translator = new T2W("EN_US"); | |
// one thousand two hundred thirty-four | |
translator.toWords(1234) |
OlderNewer