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 |
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
Due to its folder nesting Windows can’t delete the folder as its name is too long. | |
To solve this, install RimRaf: | |
[npm install rimraf -g] | |
and delete the node_modules folder easily with: | |
[rimraf node_modules] |
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
// Setup | |
var collection = { | |
"2548": { | |
"album": "Slippery When Wet", | |
"artist": "Bon Jovi", | |
"tracks": [ | |
"Let It Rock", | |
"You Give Love a Bad Name" | |
] |
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 truncateString(str, num) { | |
// Clear out that junk in your trunk | |
if (num > 3) { | |
if (str.length > num) { | |
str = str.slice(0, num - 3) + "..."; | |
} | |
return str; | |
} else { | |
str = str.slice(0, num) + "..."; | |
} |
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 confirmEnding(str, target) { | |
// "Never give up and good luck will find you." | |
// -- Falcor | |
var x = str.length - (target.length); | |
if (str.substr(x, str.length) == target) { | |
return true; | |
} else { | |
return false; | |
} | |
/*function confirmEnding(str, target) { |
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 repeatStringNumTimes(str, num) { | |
// repeat after me | |
if (num > 0) { | |
return str.repeat(num); | |
} else { | |
return ""; | |
} | |
} | |
repeatStringNumTimes("abc", 3); |
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 chunkArrayInGroups(arr, size) { | |
// first solution | |
/*var arr1 = []; | |
var arr2 = []; | |
for (var i = 0; i < arr.length; i++) { | |
if (i % size !== size - 1) | |
arr1.push(arr[i]); | |
else { | |
arr1.push(arr[i]); | |
arr2.push(arr1); |