Skip to content

Instantly share code, notes, and snippets.

View jwill9999's full-sized avatar
💭
working

Jason Williams jwill9999

💭
working
View GitHub Profile
@jwill9999
jwill9999 / index.js
Created October 10, 2017 16:46
Drop It
/*
Drop the elements of an array (first argument), starting from the front, until the predicate (second argument) returns true.
The second argument, func, is a function you'll use to test the first elements of the array to decide if you should drop it or not.
Return the rest of the array, otherwise return an empty array.
*/
function dropElements(arr, func) {
let index = arr.findIndex(func);
@jwill9999
jwill9999 / index.js
Created October 10, 2017 16:45
finders Keepers
/*
Create a function that looks through an array (first argument) and returns the first element in the array that passes a truth test (second argument).
*/
function findElement(arr, func) {
var num = arr.filter(func);
return num[0];
}
findElement([1, 2, 3, 4], function(num) {
@jwill9999
jwill9999 / index.js
Created October 10, 2017 16:43
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.
e.g. for 1 and 3 - find the smallest common multiple of both 1 and 3 that is evenly divisible by all numbers between 1 and 3.
*/
function smallestCommons(arr) {
@jwill9999
jwill9999 / index.js
Created October 10, 2017 16:41
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) {
@jwill9999
jwill9999 / index.js
Created October 10, 2017 16:40
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 10 are 1, 1, 3, and 5.
*/
var fibonacci = function(n) {
@jwill9999
jwill9999 / index.js
Created October 10, 2017 16:38
Spinal Tap Case
/*
Convert a string to spinal case. Spinal case is all-lowercase-words-joined-by-dashes.
*/
function spinalCase(str) {
var regex = /\s|_|(?=[A-Z])/;
str = str.split(regex).join('-').toLowerCase();
@jwill9999
jwill9999 / index.js
Last active October 10, 2017 16:37
convert HTML entities
/*
Convert the characters &, <, >, " (double quote), and ' (apostrophe), in a string to their corresponding HTML entities.
*/
function convertHTML(str) {
str = str.split('');
for (var i in str) {
switch (str[i]) {
case '&':
@jwill9999
jwill9999 / index.js
Created October 10, 2017 16:34
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.
*/
function uniteUnique(...arr) {
var holder = [];
@jwill9999
jwill9999 / index.js
Created October 10, 2017 16:32
Boo Who
/*
Check if a value is classified as a boolean primitive. Return true or false.
Boolean primitives are true and false.
*/
function booWho(bool) {
if (typeof bool === 'boolean') {
return true;
} else {
@jwill9999
jwill9999 / index.js
Created October 10, 2017 16:30
Missing Letter
/*
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) {
str = str.split('');
var alphabet = 'abcdefghijklmnopqrstuvwxyz';
alph = alphabet.split('');