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 / dropElements.js
Last active October 8, 2022 17:21
freeCodeCamp Intermediate Algorithm Scripting: Drop it
// Given the array arr, iterate through and remove each element
// starting from the first element (the 0 index) until the function
// func returns true when the iterated element is passed through it.
// Then return the rest of the array once the condition is satisfied,
// otherwise, arr should be returned as an empty array.
// Cannot use filter, since we need to return the rest of the array
// once the condition is met. We use a 'For' loop !
@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 / 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 / makeAPerson.js
Created June 15, 2018 21:34
freeCodeCamp Intermediate Algorithm Scripting: Make a Person
// Fill in the object constructor with the following methods below:
// getFirstName() getLastName() getFullName() setFirstName(first)
// setLastName(last) setFullName(firstAndLast)
// Run the tests to see the expected output for each method.
// The methods that take an argument must accept only one argument
// and it has to be a string.
// These methods must be the only available means of interacting with
@eday69
eday69 / checkCashRegister.js
Created June 16, 2018 21:27
freeCodeCamp JavaScript Algorithms and Data Structures Projects: Cash Register
// Design a cash register drawer function checkCashRegister()
// that accepts purchase price as the first argument (price),
// payment as the second argument (cash), and cash-in-drawer
// (cid) as the third argument.
// cid is a 2D array listing available currency.
// The checkCashRegister() function should always return an object
// with a status key and a change key.
@eday69
eday69 / telephoneCheck.js
Created June 16, 2018 16:51
freeCodeCamp JavaScript Algorithms and Data Structures Projects: Telephone Number Validator
// Return true if the passed string looks like a valid US
// phone number.
// The user may fill out the form field any way they choose
// as long as it has the format of a valid US number. The
// following are examples of valid formats for US numbers
// (refer to the tests below for other variants):
// 555-555-5555 (555)555-5555 (555) 555-5555 555 555 5555
// 5555555555 1 555 555 5555
@eday69
eday69 / rot13.js
Created June 16, 2018 15:11
freeCodeCamp JavaScript Algorithms and Data Structures Projects: Caesars Cipher
// One of the simplest and most widely known ciphers is a Caesar cipher,
// also known as a shift cipher. In a shift cipher the meanings of the
// letters are shifted by some set amount.
// A common modern use is the ROT13 cipher, where the values of the
// letters are shifted by 13 places. Thus 'A' ↔ 'N', 'B' ↔ 'O' and so on.
// Write a function which takes a ROT13 encoded string as input and
// returns a decoded string.
@eday69
eday69 / convertToRoman.js
Created June 16, 2018 03:12
freeCodeCamp JavaScript Algorithms and Data Structures Projects: Roman Numeral Converter
// Convert the given number into a roman numeral.
// All roman numerals answers should be provided in upper-case.
function convertToRoman(num) {
let thousands = ["", "M", "MM", "MMM"];
let hundreds = ["", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"];
let dozens = ["", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"];
let singles = ["", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"];
return thousands[Math.floor(num / 1000)]+
@eday69
eday69 / palindrome.js
Created June 16, 2018 02:29
freeCodeCamp JavaScript Algorithms and Data Structures Projects: Palindrome Checker
// Return true if the given string is a palindrome. Otherwise,
// return false.
// A palindrome is a word or sentence that's spelled the same
// way both forward and backward, ignoring punctuation, case,
// and spacing.
// Note
// You'll need to remove all non-alphanumeric characters (punctuation,
// spaces and symbols) and turn everything into the same case
// (lower or upper case) in order to check for palindromes.
@eday69
eday69 / orbitalPeriod.js
Created June 16, 2018 02:11
freeCodeCamp Intermediate Algorithm Scripting: Map the Debris
// Return a new array that transforms the elements' average
// altitude into their orbital periods (in seconds).
// The array will contain objects in the format {name: 'name',
// avgAlt: avgAlt}.
// You can read about orbital periods on Wikipedia.
// The values should be rounded to the nearest whole number.
// The body being orbited is Earth.
// The radius of the earth is 6367.4447 kilometers, and the GM
// value of earth is 398600.4418 km3s-2.