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
// We'll pass you an array of two numbers. Return the sum of those two numbers plus the sum of all the numbers between them. | |
// The lowest number will not always come first. | |
// This was my solution: | |
function sumAll(arr) { | |
let start=arr[0] > arr[1]?arr[1]:arr[0]; | |
let end=arr[0] > arr[1]?arr[0]:arr[1]; | |
let sum=0; | |
for (let i=start; i<=end; i++) { | |
sum+=i; |
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
// Compare two arrays and return a new array with any items only found | |
// in one of the two given arrays, but not both. In other words, return | |
// the symmetric difference of the two arrays. | |
function diffArray(arr1, arr2) { | |
return arr1.concat(arr2).filter( | |
info => !arr1.includes(info) || !arr2.includes(info)); | |
} |
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
// You will be provided with an initial array (the first argument | |
// in the destroyer function), followed by one or more arguments. | |
// Remove all elements from the initial array that are of the same | |
// value as these arguments. | |
// Note | |
// You have to use the arguments object. | |
function destroyer(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
// 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'); |
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
// 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. | |
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). |
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
// 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
// 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
// Convert the characters &, <, >, " (double quote), and ' (apostrophe), | |
// in a string to their corresponding HTML entities. | |
function convertHTML(str) { | |
// :) | |
const convertHTML={ "&": "&", | |
"<": "<", | |
">": ">", | |
"\"": """, | |
"'": "'"} |
OlderNewer