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
// A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99. | |
// Find the largest palindrome made from the product of two 3-digit numbers. | |
function isPalindrome(num) { | |
const numStr = num.toString(), | |
numStrLength = numStr.length; | |
// Loop | |
for (let i = 0; i < numStrLength / 2; i++) { | |
if (numStr[i] != numStr[numStrLength - 1 - 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
// The prime factors of 13195 are 5, 7, 13 and 29. | |
// What is the largest prime factor of the number 600851475143? | |
// Define prime factors: Well, they are factors of a number that are prime. i.e prime are numbers that are divisible by 1 and itself | |
// Solution | |
const primeFactorOps = {}; | |
primeFactorOps.cache = []; |
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
// Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: | |
// 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... | |
// By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms. | |
function fiboAddEven(start, limit) { | |
if ((typeof start !== "number" || start === 0) || typeof limit !== "number") return "Arguments supplied to fn fiboEvenAdd must be a natural integer"; | |
let fibArray = []; | |
fibArray.push(start); |
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
// Problem: If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. | |
// The sum of these multiples is 23. | |
// Find the sum of all the multiples of 3 or 5 below 1000. | |
// Solution: | |
function getSumOfMultiples(limit) { | |
// confirm limit is a number | |
if (typeof limit !== "number") return "The parameter supplied for fn getSumOfMultiples must be a valid number"; |