Armstrong Number fix
This commit is contained in:
parent
a2631210fe
commit
321c48873e
@ -333,19 +333,19 @@ function convertRomanToArabic(str) {
|
||||
|
||||
// Vérifie si un nombre fait partie des nombres d'Armstrong ou non
|
||||
function armstrongNumber(number) {
|
||||
let nombreString = number.toString();
|
||||
let nombreStringLength = nombreString.length;
|
||||
let numberString = number.toString();
|
||||
let numberStringLength = numberString.length;
|
||||
|
||||
let result = 0;
|
||||
let resultString = "";
|
||||
for (let i = 0; i < nombreStringLength; i++) {
|
||||
result = result + parseInt(nombreString[i])**nombreStringLength;
|
||||
resultString = resultString + " + " + nombreString[i] + "<sup>" + nombreStringLength + "</sup>";
|
||||
for (let i = 0; i < numberStringLength; i++) {
|
||||
result = result + parseInt(numberString[i])**numberStringLength;
|
||||
resultString = resultString + " + " + numberString[i] + "<sup>" + numberStringLength + "</sup>";
|
||||
}
|
||||
|
||||
if (result === nombre) {
|
||||
return `${formatNumberResult(nombre)} est un nombre d'Armstrong, car ${resultString.slice(2)} = ${formatNumberResult(result)}.`;
|
||||
if (result === number) {
|
||||
return `${formatNumberResult(number)} est un nombre d'Armstrong, car ${resultString.slice(2)} = ${formatNumberResult(result)}.`;
|
||||
} else {
|
||||
return `${formatNumberResult(nombre)} n'est pas un nombre d'Armstrong, car ${resultString.slice(2)} = ${formatNumberResult(result)}.`;
|
||||
return `${formatNumberResult(number)} n'est pas un nombre d'Armstrong, car ${resultString.slice(2)} = ${formatNumberResult(result)}.`;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user