This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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 '&': |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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 = []; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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(''); |