This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
// Intermediate Algorithm Scripting: Binary Agents | |
// Return an English translated sentence of the passed binary string. | |
// The binary string will be space separated. | |
function binaryAgent(str) { | |
return str.split(" ").map(letter => String.fromCharCode(parseInt(letter,2).toString())).join(""); | |
} | |
binaryAgent("01000001 01110010 01100101 01101110 00100111 01110100 00100000 01100010 01101111 01101110 01100110 01101001 01110010 01100101 01110011 00100000 01100110 01110101 01101110 00100001 00111111"); // "Aren't bonfires fun!?" |
This file contains hidden or 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 the predicate (second argument) is truthy on all | |
// elements of a collection (first argument). | |
// In other words, you are given an array collection of objects. | |
// The predicate pre will be an object property and you need to | |
// return true if its value is truthy. Otherwise, return false. | |
// In JavaScript, truthy values are values that translate to true | |
// when evaluated in a Boolean context. | |
// Remember, you can access object properties through either dot |
This file contains hidden or 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 sums two arguments together. If only | |
// one argument is provided, then return a function that expects | |
// one argument and returns the sum. | |
// For example, addTogether(2, 3) should return 5, and addTogether(2) | |
// should return a function. | |
// Calling this returned function with a single argument will then | |
// return the sum: | |
// var sumTwoAnd = addTogether(2); | |
// sumTwoAnd(3) returns 5. | |
// If either argument isn't a valid number, return undefined. |
This file contains hidden or 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
// Fill in the object constructor with the following methods below: | |
// getFirstName() getLastName() getFullName() setFirstName(first) | |
// setLastName(last) setFullName(firstAndLast) | |
// Run the tests to see the expected output for each method. | |
// The methods that take an argument must accept only one argument | |
// and it has to be a string. | |
// These methods must be the only available means of interacting with |
This file contains hidden or 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
// Return a new array that transforms the elements' average | |
// altitude into their orbital periods (in seconds). | |
// The array will contain objects in the format {name: 'name', | |
// avgAlt: avgAlt}. | |
// You can read about orbital periods on Wikipedia. | |
// The values should be rounded to the nearest whole number. | |
// The body being orbited is Earth. | |
// The radius of the earth is 6367.4447 kilometers, and the GM | |
// value of earth is 398600.4418 km3s-2. |