Simple overview of use/purpose.
An in-depth paragraph about your project and overview of use.
| // A prime number is a whole number greater than 1 with exactly two divisors: 1 and itself. | |
| // For example, 2 is a prime number because it is only divisible by 1 and 2. | |
| // In contrast, 4 is not prime since it is divisible by 1, 2 and 4. | |
| // Rewrite sumPrimes so it returns the sum of all prime numbers that are less than or equal to num. | |
| function sumPrimes(num) { | |
| let primeArr = []; | |
| for(let i = 2; i <= num; i++) { | |
| if(primeArr.every((prime) => i % prime !== 0)) | |
| primeArr.push(i); |
| // Convert a string to spinal case. Spinal case is all-lowercase-words-joined-by-dashes. | |
| // Regex + Join Method | |
| function spinalCase(str) { | |
| return str | |
| .split(/[\s_]+|(?=[A-Z])/g) | |
| .join("-") | |
| .toLowerCase(); | |
| } |
| // Function looks through an array of objects and returns an array of all objects that have matching name and value pairs. | |
| // Each name and value pair of the source object has to be present in the object from the collection. | |
| // For example, if the first argument is [{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }]. | |
| // The second argument is { last: "Capulet" }. Then you must return the third object from the array (the first argument). | |
| // Because it contains the name and its value, that was passed on as the second argument. | |
| // Solution Using Filter and Every Methods | |
| function whatIsInAName(collection, source) { | |
| // 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, ...args) { | |
| return arr.filter(elem => !args.includes(elem)) | |
| } | |
| destroyer([1, 2, 3, 1, 2, 3], 2, 3); |
| // 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. | |
| // For example, sumAll([4,1]) should return 10 because sum of all the numbers between 1 and 4 (both inclusive) is 10. | |
| function sumAll(arr) { | |
| let total = 0; | |
| if(arr[0] < arr[1]) { | |
| for(let i = arr[0]; i <= arr[1]; i++) { | |
| total = total + i; | |
| } |
| // Multiply by 11 | |
| // Given a positive number as a string, multiply the number by 11 and also return it as a string. However, there is a catch: | |
| // You are NOT ALLOWED to simply cast the numeric string into an integer! | |
| // Now, how is this challenge even possible? Despite this, there is still a way to solve it, and it involves thinking about how someone might multiply by 11 in their head. See the tips below for guidance. | |
| // Examples | |
| // multiplyBy11("11") ➞ "121" | |
| // multiplyBy11("111111111") ➞ "1222222221" |
| // Filter Out Strings from an Array | |
| // Create a function that takes an array of non-negative integers and strings and returns a new array without the strings. | |
| // Examples | |
| // filterArray([1, 2, "a", "b"]) ➞ [1, 2] | |
| // filterArray([1, "a", "b", 0, 15]) ➞ [1, 0, 15] | |
| // filterArray([1, 2, "aasf", "1", "123", 123]) ➞ [1, 2, 123] | |
| // Notes | |
| // Zero is a non-negative integer. | |
| // The given array only has integers and strings. |
| Given a time in -hour AM/PM format, convert it to military (24-hour) time. | |
| Note: - 12:00:00AM on a 12-hour clock is 00:00:00 on a 24-hour clock. | |
| - 12:00:00PM on a 12-hour clock is 12:00:00 on a 24-hour clock. | |
| Example | |
| Return '12:01:00'. |
| function fibonacciGenerator(n) { | |
| var fibArray = []; //create empty array to push sequence into | |
| if (n == 1) { | |
| fibArray = [0]; //sets first element to 0 | |
| } | |
| else if (n == 2) { | |
| fibArray = [0, 1]; //sets second element to 1 | |
| } | |
| else { |