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 / SteamRoller.js
Created June 15, 2018 17:53
freeCodeCamp Intermediate Algorithm Scripting: Binary Agents
// Intermediate Algorithm Scripting: Binary Agents
// Return an English translated sentence of the passed binary string.
// The binary string will be space separated.
function binaryAgent(str) {
return str.split(" ").map(letter => String.fromCharCode(parseInt(letter,2).toString())).join("");
}
binaryAgent("01000001 01110010 01100101 01101110 00100111 01110100 00100000 01100010 01101111 01101110 01100110 01101001 01110010 01100101 01110011 00100000 01100110 01110101 01101110 00100001 00111111"); // "Aren't bonfires fun!?"
@eday69
eday69 / steamrollArray.js
Last active June 15, 2018 17:53
freeCodeCamp Intermediate Algorithm Scripting: Steamroller
// Flatten a nested array. You must account for varying levels of nesting.
function steamrollArray(arr) {
// I'm a steamroller, baby
return arr.reduce((acc, val) => Array.isArray(val) ? acc.concat(steamrollArray(val)) : acc.concat(val), []);
}
steamrollArray([1, [2], [3, [[4]]]]); // [1, 2, 3, 4]
steamrollArray([[["a"]], [["b"]]]); // ["a", "b"].
@eday69
eday69 / smallestCommons.js
Last active June 15, 2018 17:54
freeCodeCamp Intermediate Algorithm Scripting: Smallest Common Multiple
// Find the smallest common multiple of the provided parameters
// that can be evenly divided by both, as well as by all sequential
// numbers in the range between these parameters.
// The range will be an array of two numbers that will not necessarily
// be in numerical order.
// For example, if given 1 and 3, find the smallest common multiple of
// both 1 and 3 that is also evenly divisible by all numbers between 1
@eday69
eday69 / sumPrimes.js
Last active June 15, 2018 17:55
freeCodeCamp Intermediate Algorithm Scripting: Sum All Primes
// Sum all the prime numbers up to and including the provided number.
// A prime number is defined as a number greater than one and having
// only two divisors, one and itself. For example, 2 is a prime number
// because it's only divisible by one and two.
// The provided number may not be a prime.
function sumPrimes(num) {
let ourSum=0; // We start with one, prime for 1
@eday69
eday69 / sumFibs.js
Last active June 15, 2018 17:55
freeCodeCamp Intermediate Algorithm Scripting: Sum All Odd Fibonacci Numbers
// Given a positive integer num, return the sum of all odd
// Fibonacci numbers that are less than or equal to num.
// The first two numbers in the Fibonacci sequence are 1 and
// 1. Every additional number in the sequence is the sum of
// the two previous numbers. The first six numbers of the
// Fibonacci sequence are 1, 1, 2, 3, 5 and 8.
// For example, sumFibs(10) should return 10 because all odd
// Fibonacci numbers less than or equal to 10 are 1, 1, 3, and 5.
@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;"}
@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 / 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 / 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 / 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.