📦 NEW: Ajout de la fonction findLongestWord
This commit is contained in:
		
							
								
								
									
										3
									
								
								.github/backup.sql
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								.github/backup.sql
									
									
									
									
										vendored
									
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							| @@ -12,6 +12,7 @@ const randomQuote                     = require('./main/randomQuote'); | ||||
| const linkShortener                   = require('./main/linkShortener'); | ||||
| const rightPriceOutput                = require('./main/rightPrice'); | ||||
| const isPalindromeOutput              = require('./main/isPalindrome'); | ||||
| const findLongestWordOutput           = require('./main/findLongestWord'); | ||||
|  | ||||
| const functionObject = { | ||||
|     randomNumber             : randomNumberOutput, | ||||
| @@ -27,7 +28,8 @@ const functionObject = { | ||||
|     randomQuote              : randomQuote, | ||||
|     linkShortener            : linkShortener, | ||||
|     rightPrice               : rightPriceOutput, | ||||
|     isPalindrome             : isPalindromeOutput | ||||
|     isPalindrome             : isPalindromeOutput, | ||||
|     findLongestWord          : findLongestWordOutput, | ||||
| }; | ||||
|  | ||||
| // Choisi la fonction à exécuter | ||||
|   | ||||
							
								
								
									
										39
									
								
								api/assets/functions/main/findLongestWord.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								api/assets/functions/main/findLongestWord.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,39 @@ | ||||
| const errorHandling      = require('../../utils/errorHandling'); | ||||
| const { requiredFields } = require('../../config/errors'); | ||||
|  | ||||
| /** | ||||
|  * @description Renvoie le mot le plus long d'une chaîne de caractères | ||||
|  * @param {string} string  | ||||
|  * @returns {string} | ||||
|  * @example findLongestWord('Chaîne de caractères') → 'caractères' | ||||
|  */ | ||||
| function findLongestWord(string) { | ||||
|     const arrayString = string.split(" "); | ||||
|     let stringLength = 0; | ||||
|     let result = ""; | ||||
|  | ||||
|     arrayString.forEach((element) => { | ||||
|         if (element.length > stringLength) { | ||||
|             result = element; | ||||
|             stringLength = element.length; | ||||
|         } | ||||
|     }); | ||||
|  | ||||
|     return result; | ||||
| } | ||||
|  | ||||
| /* OUTPUTS */ | ||||
| module.exports = findLongestWordOutput = ({ res, next }, argsObject) => { | ||||
|     const { string } = argsObject; | ||||
|      | ||||
|     // S'il n'y a pas les champs obligatoire | ||||
|     if (!(string)) { | ||||
|         return errorHandling(next, requiredFields); | ||||
|     } | ||||
|  | ||||
|     const result = findLongestWord(string); | ||||
|     return res.status(200).json({ | ||||
|         result, | ||||
|         resultHTML: `<p>Le mot le plus long est : <br/>"${result}"</p>` | ||||
|     }); | ||||
| } | ||||
		Reference in New Issue
	
	Block a user