Skip to content

Instantly share code, notes, and snippets.

View eday69's full-sized avatar

Eric Day eday69

  • Calgary, AB CANADA
View GitHub Profile
@eday69
eday69 / translatePigLatin.js
Last active June 15, 2018 17:57
freeCodeCamp Intermediate Algorithm Scripting: Pig Latin
// Translate the provided string to pig latin.
// Pig Latin takes the first consonant (or consonant cluster) of
// an English word, moves it to the end of the word and suffixes an "ay".
// If a word begins with a vowel you just add "way" to the end.
// Input strings are guaranteed to be English words in all lowercase.
@eday69
eday69 / spinalCase.js
Last active November 19, 2020 18:48
freeCodeCamp Intermediate Algorithm Scripting: Spinal Tap Case
// Convert a string to spinal case. Spinal case is all-lowercase-words-joined-by-dashes.
function spinalCase(str) {
// "It's such a fine line between stupid, and clever."
// --David St. Hubbins
return str.split(/\s|_|(?=[A-Z])/).join("-").toLowerCase();
}
spinalCase('This Is Spinal Tap');
@eday69
eday69 / destroyer.js
Last active June 15, 2018 17:58
freeCodeCamp Intermediate Algorithm Scripting: Seek and Destroy
// You will be provided with an initial array (the first argument
// in the destroyer function), followed by one or more arguments.
// Remove all elements from the initial array that are of the same
// value as these arguments.
// Note
// You have to use the arguments object.
function destroyer(arr) {
@eday69
eday69 / diffArray.js
Last active June 15, 2018 17:58
freeCodeCamp Intermediate Algorithm Scripting: Diff Two Arrays
// Compare two arrays and return a new array with any items only found
// in one of the two given arrays, but not both. In other words, return
// the symmetric difference of the two arrays.
function diffArray(arr1, arr2) {
return arr1.concat(arr2).filter(
info => !arr1.includes(info) || !arr2.includes(info));
}
@eday69
eday69 / sumAll.js
Last active June 15, 2018 17:59
Intermediate Algorithm Scripting: Sum All Numbers in a Range
// We'll pass you an array of two numbers. Return the sum of those two numbers plus the sum of all the numbers between them.
// The lowest number will not always come first.
// This was my solution:
function sumAll(arr) {
let start=arr[0] > arr[1]?arr[1]:arr[0];
let end=arr[0] > arr[1]?arr[0]:arr[1];
let sum=0;
for (let i=start; i<=end; i++) {
sum+=i;