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
|
// Vérifie si un nombre fait partie des nombres d'Armstrong ou non
|
||||||
function armstrongNumber(number) {
|
function armstrongNumber(number) {
|
||||||
let nombreString = number.toString();
|
let numberString = number.toString();
|
||||||
let nombreStringLength = nombreString.length;
|
let numberStringLength = numberString.length;
|
||||||
|
|
||||||
let result = 0;
|
let result = 0;
|
||||||
let resultString = "";
|
let resultString = "";
|
||||||
for (let i = 0; i < nombreStringLength; i++) {
|
for (let i = 0; i < numberStringLength; i++) {
|
||||||
result = result + parseInt(nombreString[i])**nombreStringLength;
|
result = result + parseInt(numberString[i])**numberStringLength;
|
||||||
resultString = resultString + " + " + nombreString[i] + "<sup>" + nombreStringLength + "</sup>";
|
resultString = resultString + " + " + numberString[i] + "<sup>" + numberStringLength + "</sup>";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result === nombre) {
|
if (result === number) {
|
||||||
return `${formatNumberResult(nombre)} est un nombre d'Armstrong, car ${resultString.slice(2)} = ${formatNumberResult(result)}.`;
|
return `${formatNumberResult(number)} est un nombre d'Armstrong, car ${resultString.slice(2)} = ${formatNumberResult(result)}.`;
|
||||||
} else {
|
} 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