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 / 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;
@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 / 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 / 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 / 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 / myReplace.js
Last active June 15, 2018 17:57
freeCodeCamp Intermediate Algorithm Scripting: Search and Replace
// Perform a search and replace on the sentence using the arguments
// provided and return the new sentence.
// First argument is the sentence to perform the search and replace on.
// Second argument is the word that you will be replacing (before).
// Third argument is what you will be replacing the second argument
// with (after).
@eday69
eday69 / pairElement.js
Last active June 15, 2018 17:56
freeCodeCamp Intermediate Algorithm Scripting: DNA Pairing
// The DNA strand is missing the pairing element. Take each character,
// get its pair, and return the results as a 2d array.
// Base pairs are a pair of AT and CG. Match the missing element to the
// provided character.
// Return the provided character as the first element in each array.
// For example, for the input GCG, return [["G", "C"], ["C","G"],["G", "C"]]
@eday69
eday69 / fearNotLetter.js
Last active August 28, 2021 22:44
freeCodeCamp Intermediate Algorithm Scripting: Missing letters
// Find the missing letter in the passed letter range and return it.
// If all letters are present in the range, return undefined.
function fearNotLetter(str) {
let lastLetter=str.charCodeAt(0);
let missingLetter;
for (let i=1; i<str.length; i++) {
let currentLetter=str.charCodeAt(i);
console.log(lastLetter, currentLetter);
if ((lastLetter+1) < currentLetter) {
@eday69
eday69 / uniteUnique.js
Last active June 15, 2018 17:56
freeCodeCamp Intermediate Algorithm Scripting: Sorted Union
// Write a function that takes two or more arrays and returns a new
// array of unique values in the order of the original provided arrays.
// In other words, all values present from all arrays should be included
// in their original order, but with no duplicates in the final array.
// The unique numbers should be sorted by their original order, but the
// final array should not be sorted in numerical order.
@eday69
eday69 / convertHTML.js
Last active June 15, 2018 17:55
freeCodeCamp Intermediate Algorithm Scripting: Convert HTML Entities
// Convert the characters &, <, >, " (double quote), and ' (apostrophe),
// in a string to their corresponding HTML entities.
function convertHTML(str) {
// &colon;&rpar;
const convertHTML={ "&": "&amp;",
"<": "&lt;",
">": "&gt;",
"\"": "&quot;",
"'": "&apos;"}