mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-06 17:50:39 +08:00
fix the string method problem
This commit is contained in:
@ -29,10 +29,14 @@ const CheckKishnamurthyNumber = (number) => {
|
|||||||
// create a variable to store the sum of all digits factorial.
|
// create a variable to store the sum of all digits factorial.
|
||||||
let sumOfAllDigitFactorial = 0
|
let sumOfAllDigitFactorial = 0
|
||||||
// convert the number to string for convenience.
|
// convert the number to string for convenience.
|
||||||
String(number).split('').map(digit => {
|
let newNumber = number
|
||||||
// split one by one digit and calculate factorial and store to the variable.
|
// Extract number digits using the remainder method.
|
||||||
return (sumOfAllDigitFactorial += factorial(Number(digit)))
|
while (newNumber > 0) {
|
||||||
})
|
const lastDigit = newNumber % 10
|
||||||
|
// calculate each digit factorial.
|
||||||
|
sumOfAllDigitFactorial += factorial(lastDigit)
|
||||||
|
newNumber = Math.floor(newNumber / 10)
|
||||||
|
}
|
||||||
// if the sumOftheFactorial is equal to the given number it means the number is a Krishnamurthy number.
|
// if the sumOftheFactorial is equal to the given number it means the number is a Krishnamurthy number.
|
||||||
return sumOfAllDigitFactorial === number
|
return sumOfAllDigitFactorial === number
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user