mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2026-03-13 15:21:15 +08:00
fixed some spellings
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
Modified from:
|
||||
https://github.com/TheAlgorithms/Python/blob/master/maths/binary_exponentiation.py
|
||||
|
||||
Explaination:
|
||||
Explanation:
|
||||
https://en.wikipedia.org/wiki/Exponentiation_by_squaring
|
||||
*/
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
Problem statement and Explanation : https://www.geeksforgeeks.org/check-if-a-number-is-a-krishnamurthy-number-or-not-2/
|
||||
|
||||
krishnamurthy number is a number the sum of the all fectorial of the all dights is equal to the number itself.
|
||||
krishnamurthy number is a number the sum of the all factorial of the all dights is equal to the number itself.
|
||||
145 => 1! + 4! + 5! = 1 + 24 + 120 = 145
|
||||
*/
|
||||
|
||||
// factorail utility method.
|
||||
// factorial utility method.
|
||||
const factorial = (n) => {
|
||||
let fact = 1
|
||||
while (n !== 0) {
|
||||
@@ -18,7 +18,7 @@ const factorial = (n) => {
|
||||
/**
|
||||
* krishnamurthy number is a number the sum of the factorial of the all dights is equal to the number itself.
|
||||
* @param {Number} number a number for checking is krishnamurthy number or not.
|
||||
* @returns return correspond boolean vlaue, if the number is krishnamurthy number return `true` else return `false`.
|
||||
* @returns return correspond boolean value, if the number is krishnamurthy number return `true` else return `false`.
|
||||
* @example 145 => 1! + 4! + 5! = 1 + 24 + 120 = 145
|
||||
*/
|
||||
const CheckKishnamurthyNumber = (number) => {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
const digitSum = (num) => {
|
||||
// sum will store sum of digits of a number
|
||||
let sum = 0
|
||||
// while will run untill num become 0
|
||||
// while will run until num become 0
|
||||
while (num) {
|
||||
sum += num % 10
|
||||
num = parseInt(num / 10)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
Modified from:
|
||||
https://github.com/TheAlgorithms/Python/blob/master/maths/binary_exp_mod.py
|
||||
|
||||
Explaination:
|
||||
Explanation:
|
||||
https://en.wikipedia.org/wiki/Exponentiation_by_squaring
|
||||
*/
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Wikipedia: https://en.wikipedia.org/wiki/Monte_Carlo_method
|
||||
// Video Explaination: https://www.youtube.com/watch?v=ELetCV_wX_c
|
||||
// Video Explanation: https://www.youtube.com/watch?v=ELetCV_wX_c
|
||||
|
||||
const piEstimation = (iterations = 100000) => {
|
||||
let circleCounter = 0
|
||||
|
||||
@@ -2,7 +2,7 @@ const sieveOfEratosthenes = (n) => {
|
||||
/*
|
||||
* Calculates prime numbers till a number n
|
||||
* :param n: Number upto which to calculate primes
|
||||
* :return: A boolean list contaning only primes
|
||||
* :return: A boolean list containing only primes
|
||||
*/
|
||||
const primes = new Array(n + 1)
|
||||
primes.fill(true) // set all as true initially
|
||||
|
||||
@@ -17,7 +17,7 @@ function sumOfDigitsUsingString (number) {
|
||||
}
|
||||
|
||||
/*
|
||||
The input is divided by 10 in each iteraction, till the input is equal to 0
|
||||
The input is divided by 10 in each iteration, till the input is equal to 0
|
||||
The sum of all the digits is returned (The res variable acts as a collector, taking the remainders on each iteration)
|
||||
*/
|
||||
function sumOfDigitsUsingLoop (number) {
|
||||
|
||||
@@ -6,20 +6,20 @@ import {
|
||||
FibonacciMatrixExpo
|
||||
} from '../Fibonacci'
|
||||
|
||||
describe('Fibonanci', () => {
|
||||
it('should return an array of numbers for FibonnaciIterative', () => {
|
||||
describe('Fibonacci', () => {
|
||||
it('should return an array of numbers for FibonacciIterative', () => {
|
||||
expect(FibonacciIterative(5)).toEqual(
|
||||
expect.arrayContaining([1, 1, 2, 3, 5])
|
||||
)
|
||||
})
|
||||
|
||||
it('should return an array of numbers for FibonnaciRecursive', () => {
|
||||
it('should return an array of numbers for FibonacciRecursive', () => {
|
||||
expect(FibonacciRecursive(5)).toEqual(
|
||||
expect.arrayContaining([1, 1, 2, 3, 5])
|
||||
)
|
||||
})
|
||||
|
||||
it('should return number for FibonnaciRecursiveDP', () => {
|
||||
it('should return number for FibonacciRecursiveDP', () => {
|
||||
expect(FibonacciRecursiveDP(5)).toBe(5)
|
||||
})
|
||||
|
||||
@@ -29,7 +29,7 @@ describe('Fibonanci', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('should return number for FibonnaciMatrixExpo', () => {
|
||||
it('should return number for FibonacciMatrixExpo', () => {
|
||||
expect(FibonacciMatrixExpo(0)).toBe(0)
|
||||
expect(FibonacciMatrixExpo(1)).toBe(1)
|
||||
expect(FibonacciMatrixExpo(2)).toBe(1)
|
||||
|
||||
Reference in New Issue
Block a user