Skip to content

Instantly share code, notes, and snippets.

View sebshub's full-sized avatar
💭
I may be slow to respond.

Sebastian sebshub

💭
I may be slow to respond.
View GitHub Profile
@sebshub
sebshub / 0_reuse_code.js
Created March 3, 2016 04:45
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@sebshub
sebshub / gist:fe4d4524f69b40dc06b4e4b9b12e80b4
Created April 25, 2016 08:41
How to delete node_modules folder on Windows machine?
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]
@sebshub
sebshub / RecordCollectionFCC.js
Created November 18, 2016 06:14
Record Collection JSON exercise for handling incomplete data
// Setup
var collection = {
"2548": {
"album": "Slippery When Wet",
"artist": "Bon Jovi",
"tracks": [
"Let It Rock",
"You Give Love a Bad Name"
]
@sebshub
sebshub / TruncateAstring.js
Created November 25, 2016 11:18
Truncate a string FCC
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) + "...";
}
@sebshub
sebshub / ConfirmTheEnding.js
Created December 2, 2016 21:55
Confirm the Ending "FCC" Check if a string (first argument, str) ends with the given target string (second argument, target) without using .endsWith()
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) {
@sebshub
sebshub / RepeatAstring.js
Created December 2, 2016 22:01
Repeat a string repeat a string FCC
function repeatStringNumTimes(str, num) {
// repeat after me
if (num > 0) {
return str.repeat(num);
} else {
return "";
}
}
repeatStringNumTimes("abc", 3);
@sebshub
sebshub / ChunkyMonkey.js
Created December 2, 2016 22:06
Chunky Monkey FCC freecodecamp exercise 3 solutions
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);