Skip to content

Instantly share code, notes, and snippets.

View having-fun-coding's full-sized avatar

Jeffrey Collins having-fun-coding

View GitHub Profile
@having-fun-coding
having-fun-coding / bouncer.js
Created May 16, 2015 17:14
Falsey Bouncer | Free Code Camp
function bouncer(arr) {
arr = arr.filter(function (n) {
return (n !== undefined && n !== null && n !== false && n !== 0 && n !== "" && n!== isNaN); });
return arr;
}
Return the remaining elements of an array after chopping off n elements from the head.
Here are some helpful links:
Array.slice()
Array.splice()
@having-fun-coding
having-fun-coding / chunkymonkey.js
Last active November 23, 2020 18:25
Split Array into a Multidimensional Array
function chunk (array, length) {
var chunkarr = [],
i = 0,
n = array.length;
while (i < n) {
chunkarr.push(array.slice(i, i += length));
}
@having-fun-coding
having-fun-coding / readMe.txt
Created May 11, 2015 19:20
Truncate a String | Free Code Camp | Bonfire
Truncate a string (first argument) if it is longer than the given maximum string length (second argument). Return the truncated string with a '...' ending.
Note that the three dots at the end add to the string length.
Here are some helpful links:
String.slice()
@having-fun-coding
having-fun-coding / readMe.txt
Last active August 29, 2015 14:20
Repeat a String | Free Code Camp | Bonfire
Repeat a given string (first argument) n times (second argument). Return an empty string if n is a negative number.
Here are some helpful links:
Global String Object
The '&' is a Bitwise AND. >> is Bitwise right shift operator. Bitwise shift operators Operations to shift all bits of the operand.
Bitwise operators (&,|,^) treat their operands as a set of 32 bits (zeros and ones) and return standard JavaScript numerical values.
@having-fun-coding
having-fun-coding / end.js
Created May 10, 2015 20:35
Confirm the Ending
function end(str, target) {
return str.substring(str.length-target.length) == target;
}
@having-fun-coding
having-fun-coding / Readme.txt
Created May 9, 2015 18:06
Return Largest Numbers in Arrays
Return an array consisting of the largest number from each provided sub-array. For simplicity, the provided array will contain exactly 4 sub-arrays.
@having-fun-coding
having-fun-coding / Readme.txt
Created May 9, 2015 01:23
Title Case a Sentence | FreeCodeCamp
Make the first letter of each word uppercase and the other letters of the word lowercase.
@having-fun-coding
having-fun-coding / longestWord.js
Created May 8, 2015 19:37
findLongestWord | Free Code Camp | Bonfire Challenge
function findLongestWord(str) {
longWords = str.split(' ');
var longest = longWords[0].length;
for (var i = 0; i < longWords.length; i++) {
if (longWords[i].length > longest) {
longest = longWords[i].length;
}
}
@having-fun-coding
having-fun-coding / palindrome.js
Last active August 29, 2015 14:20
Palindrome at FCC
function palindrome (str) {
var string = (str+'').replace(/[\.,-\/#!$%\^&\*;:{}=\-_`~\ ()]/g,"").replace(/\s/g, "").toLowerCase();
return string === (string.split('').reverse().join(''));
}