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
// 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"]. |
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 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 ! |
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. | |
// 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 |
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) { | |
let ourSum=0; // We start with one, prime for 1 |
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 or equal to 10 are 1, 1, 3, and 5. |
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) { | |
// :) | |
const convertHTML={ "&": "&", | |
"<": "<", | |
">": ">", | |
"\"": """, | |
"'": "'"} |
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. | |
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) { | |
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) { |
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
// 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"]] |
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
// 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). |