New function : armstrongNumber
This commit is contained in:
		| @@ -26,6 +26,7 @@ Le projet est disponible sur [function.divlo.fr](https://function.divlo.fr/). | ||||
| | **utf8ToBin(s)** | UTF-8 vers Binaire | - s : la valeur à convertir  | | ||||
| | **binToUtf8(s)** | Binaire vers UTF-8 | - s : la valeur à convertir  | | ||||
| | **convertRomanArabicNumbers(nombre)** | Convertis un nombre arabe en nombre romain. | - nombre : le nombre à convertir  | | ||||
| | **armstrongNumber(nombre)** | Vérifie si un nombre fait partie des nombres d'Armstrong ou non. | - nombre : le nombre à tester  | | ||||
|  | ||||
| ## La liste des Fonctions Annexes :    | ||||
| | Nom | Description | Paramètre(s) | | ||||
|   | ||||
							
								
								
									
										
											BIN
										
									
								
								img/function-image/armstrongNumber.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								img/function-image/armstrongNumber.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 141 KiB | 
| @@ -73,6 +73,11 @@ switch ($currentpage) { | ||||
|         $description = "Convertis un nombre arabe en nombre romain."; | ||||
|         $image = 'https://function.divlo.fr/img/function-image/convertRomanArabicNumbers.png'; | ||||
|         break; | ||||
|     case '/views/function-views/armstrongNumber.php': | ||||
|         $title = "Nombre d'Armstrong"; | ||||
|         $description = "Un nombre d'<a href='https://fr.wikipedia.org/wiki/Nombre_narcissique' target='_blank'>Armstrong</a> est un nombre qui est égal à la somme de ses chiffres portés à la puissance du nombre de chiffres le composant. Cette fonction permet de savoir si un nombre fait partie des nombres d'Armstrong ou non."; | ||||
|         $image = 'https://function.divlo.fr/img/function-image/armstrongNumber.png'; | ||||
|         break; | ||||
|     default: | ||||
|         $title = 'Erreur 404'; | ||||
|         $description = "Cette page n'existe pas!"; | ||||
|   | ||||
| @@ -311,4 +311,23 @@ function convertRomanArabicNumbers(nombre) { | ||||
|     }) | ||||
|  | ||||
|     return chiffresRomains; | ||||
| } | ||||
|  | ||||
| // Vérifie si un nombre fait partie des nombres d'Armstrong ou non  | ||||
| function armstrongNumber(nombre) { | ||||
|     let nombreString = nombre.toString(); | ||||
|     let nombreStringLength = nombreString.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>"; | ||||
|     } | ||||
|  | ||||
|     if (result === nombre) { | ||||
|         return `${formatNumberResult(nombre)} 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)}.`; | ||||
|     } | ||||
| } | ||||
| @@ -225,6 +225,22 @@ $(function () { | ||||
|         } | ||||
|     }); | ||||
|  | ||||
|     $("#submitArmstrongNumber").click(function()  | ||||
|     { | ||||
|         let numbersValue = $('#numberToTest').val(); | ||||
|  | ||||
|         if(isEmptyValue(numbersValue)) { | ||||
|             $('.results').html(emptyMessageError); | ||||
|         } | ||||
|         else if (!isNaN(parseInt(numbersValue))) {  | ||||
|             let result = armstrongNumber(parseFloat(numbersValue.replace(/\s/g,'')));  | ||||
|             $('.results').html(result); | ||||
|         } | ||||
|         else { | ||||
|             $('.results').html(messageError); | ||||
|         } | ||||
|     }); | ||||
|  | ||||
|  | ||||
|     /* Permet d'afficher l'heure en temps réel sur le footer */ | ||||
|     window.onload = realDateTime('realDateTime'); | ||||
|   | ||||
| @@ -56,6 +56,10 @@ | ||||
|                         <td><a href="./function-views/convertRomanArabicNumbers.php">Conversion d'un nombre arabe en nombre romain</a></td> | ||||
|                         <td>Convertis un nombre arabe en nombre romain.</td>  | ||||
|                     </tr> | ||||
|                     <tr> | ||||
|                         <td><a href="./function-views/armstrongNumber.php">Nombre d'Armstrong</a></td> | ||||
|                         <td>Vérifie si un nombre fait partie des nombres d'Armstrong ou non.</td>  | ||||
|                     </tr> | ||||
|                 </tbody> | ||||
|             </table> | ||||
|     </div> | ||||
|   | ||||
							
								
								
									
										30
									
								
								views/function-views/armstrongNumber.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								views/function-views/armstrongNumber.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,30 @@ | ||||
| <!-- Config --> | ||||
| <?php include("../../php/config.php");?> | ||||
|  | ||||
| <!-- Header --> | ||||
| <?php include("../../incl/header.php");?> | ||||
|  | ||||
| <!-- Page Content --> | ||||
| <div class="container"> | ||||
|   <h1><span class="important"><?php echo $title?></span> :</h1> | ||||
|   <p class="pt-3 text-center"><?php echo $description?></p> | ||||
|   <div class="text-center"> | ||||
|     <img class="function-image" src="/img/function-image/armstrongNumber.png" alt="Nombre d'Armstrong"> | ||||
|   </div> | ||||
|   <div class="form-group"> | ||||
| 		<label for="numberToTest">Entrez votre nombre :</label> | ||||
|         <textarea name="numberToTest" type="text" id="numberToTest" placeholder="(e.g : 153)" class="form-control"></textarea> | ||||
|         <br> | ||||
|         <div class="form-row text-center"> | ||||
|             <div class="col-12"> | ||||
|                 <br> | ||||
|                 <button type="submit" id="submitArmstrongNumber" class="btn btn-dark text-center">Envoyer</button> | ||||
|             </div> | ||||
|         </div> | ||||
|         <br> <br> | ||||
| 		<p class="results text-center"></p> | ||||
|     </div> | ||||
| </div> | ||||
|  | ||||
| <!-- Footer --> | ||||
| <?php include("../../incl/footer.php");?> | ||||
| @@ -13,7 +13,7 @@ | ||||
|   </div> | ||||
|   <div class="form-group"> | ||||
| 		<label for="numbersArabic">Entrez votre nombre :</label> | ||||
|         <input name="numbersArabic" type="text" id="numbersArabic" placeholder="(e.g : 50')" class="form-control"> | ||||
|         <input name="numbersArabic" type="text" id="numbersArabic" placeholder="(e.g : 50)" class="form-control"> | ||||
|         <div class="form-row text-center"> | ||||
|             <div class="col-12"> | ||||
|                 <br> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user