31 lines
92 KiB
SQL
31 lines
92 KiB
SQL
/* categories */
|
|
INSERT INTO `categories` (`id`, `name`, `color`, `createdAt`, `updatedAt`) VALUES
|
|
(1, '✨ Utilitaires', '#720fc0', '2020-03-20 00:00:00', '2020-03-20 00:00:00'),
|
|
(2, '💻 Algorithmes', '#0a4c82', '2020-03-20 00:00:00', '2020-03-20 00:00:00'),
|
|
(3, '🕹️ Jeux', '#a10b0b', '2020-03-20 00:00:00', '2020-03-20 00:00:00'),
|
|
(4, '📝 Divers', '#333434', '2020-03-20 00:00:00', '2020-03-20 00:00:00');
|
|
|
|
/* functions */
|
|
INSERT INTO `functions` (`id`, `title`, `slug`, `description`, `image`, `type`, `article`, `utilizationForm`, `isOnline`, `createdAt`, `updatedAt`, `categorieId`) VALUES
|
|
(1, 'Météo', 'weatherRequest', 'Affiche la météo et l\'heure locale.', '/images/functions/weatherRequest.png', 'form', '<p>Pour une meilleure précision, je recommande de préciser le pays de la ville. Il faut rentrer le nom anglais de la ville (s\"il est différent qu\"en français).</p><p>Exemples : Paris, FR - London, UK - Moscow, RU - etc.</p><p>La météo est récupérée grâce à l\"API <a rel=\"noopener noreferrer\" target=\"_blank\" href=\"https://openweathermap.org/\">openweathermap.org</a>, une simple requête GET.</p>', '[{\"name\": \"cityName\", \"type\": \"text\", \"label\": \"Entrez le nom d\'une ville :\", \"placeholder\": \"(e.g : Paris, FR)\"}]', 1, '2019-08-16 00:00:00', '2020-05-08 13:43:26', 1),
|
|
(2, 'Nombre aléatoire', 'randomNumber', 'Génère un nombre aléatoire entre un minimum inclus et un maximum inclus.', '/images/functions/randomNumber.png', 'form', '<p>Simple fonction très utile dans de nombreux cas, qui permet de générer un nombre aléatoire entre un nombre minimum et un nombre maximum :</p><div class=\"vscode-editor\" style=\"color: #d4d4d4;background-color: #1e1e1e;font-family: Consolas, \'Courier New\', monospace;font-weight: normal;font-size: 14px;line-height: 19px;white-space: pre;\"><div><span style=\"color: #569cd6;\">function</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #dcdcaa;\">randomNumber</span><span style=\"color: #d4d4d4;\">(</span><span style=\"color: #9cdcfe;\">min</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #9cdcfe;\">max</span><span style=\"color: #d4d4d4;\">) {</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #c586c0;\">return</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #4ec9b0;\">Math</span><span style=\"color: #d4d4d4;\">.</span><span style=\"color: #dcdcaa;\">floor</span><span style=\"color: #d4d4d4;\">(</span><span style=\"color: #4ec9b0;\">Math</span><span style=\"color: #d4d4d4;\">.</span><span style=\"color: #dcdcaa;\">random</span><span style=\"color: #d4d4d4;\">() * (</span><span style=\"color: #9cdcfe;\">max</span><span style=\"color: #d4d4d4;\"> - </span><span style=\"color: #9cdcfe;\">min</span><span style=\"color: #d4d4d4;\"> +</span><span style=\"color: #b5cea8;\">1</span><span style=\"color: #d4d4d4;\">)) + </span><span style=\"color: #9cdcfe;\">min</span><span style=\"color: #d4d4d4;\">;</span></div><div><span style=\"color: #d4d4d4;\">}</span></div></div>', '[{\"name\": \"min\", \"type\": \"integer\", \"label\": \"Entrez la valeur minimale :\", \"placeholder\": \"(e.g : 1)\"}, {\"name\": \"max\", \"type\": \"integer\", \"label\": \"Entrez la valeur maximale :\", \"placeholder\": \"(e.g : 100)\"}]', 1, '2019-08-16 00:00:00', '2020-05-08 13:23:22', 2),
|
|
(3, 'Quel âge avez-vous ?', 'calculateAge', 'Calcule l\'âge selon la date de naissance.', '/images/functions/calculateAge.png', 'form', '<p>Grâce à la librairie \"Moment.js\" c\"est très simple : </p><div class=\"vscode-editor\" style=\"color: #d4d4d4;background-color: #1e1e1e;font-family: Consolas, \'Courier New\', monospace;font-weight: normal;font-size: 14px;line-height: 19px;white-space: pre;\"><div><span style=\"color: #569cd6;\">function</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #dcdcaa;\">calculateAge</span><span style=\"color: #d4d4d4;\">({ </span><span style=\"color: #9cdcfe;\">birthDateDay</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #9cdcfe;\">birthDateMonth</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #9cdcfe;\">birthDateYear</span><span style=\"color: #d4d4d4;\"> }) {</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #569cd6;\">const</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #51b6c4;\">currentDate</span><span style=\"color: #d4d4d4;\"> = </span><span style=\"color: #569cd6;\">new</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #4ec9b0;\">Date</span><span style=\"color: #d4d4d4;\">();</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #569cd6;\">const</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #51b6c4;\">day</span><span style=\"color: #d4d4d4;\"> = </span><span style=\"color: #9cdcfe;\">currentDate</span><span style=\"color: #d4d4d4;\">.</span><span style=\"color: #dcdcaa;\">getDate</span><span style=\"color: #d4d4d4;\">();</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #569cd6;\">const</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #51b6c4;\">month</span><span style=\"color: #d4d4d4;\"> = </span><span style=\"color: #9cdcfe;\">currentDate</span><span style=\"color: #d4d4d4;\">.</span><span style=\"color: #dcdcaa;\">getMonth</span><span style=\"color: #d4d4d4;\">();</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #569cd6;\">const</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #51b6c4;\">currentDateMoment</span><span style=\"color: #d4d4d4;\"> = </span><span style=\"color: #dcdcaa;\">moment</span><span style=\"color: #d4d4d4;\">([</span><span style=\"color: #9cdcfe;\">currentDate</span><span style=\"color: #d4d4d4;\">.</span><span style=\"color: #dcdcaa;\">getFullYear</span><span style=\"color: #d4d4d4;\">(), </span><span style=\"color: #9cdcfe;\">month</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #9cdcfe;\">day</span><span style=\"color: #d4d4d4;\">]);</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #569cd6;\">const</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #51b6c4;\">birthDateMoment</span><span style=\"color: #d4d4d4;\"> = </span><span style=\"color: #dcdcaa;\">moment</span><span style=\"color: #d4d4d4;\">([</span><span style=\"color: #9cdcfe;\">birthDateYear</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #9cdcfe;\">birthDateMonth</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #9cdcfe;\">birthDateDay</span><span style=\"color: #d4d4d4;\">]);</span></div><br><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #6a9955;\">// Calcule l\'âge - Moment.js</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #569cd6;\">const</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #51b6c4;\">ageYears</span><span style=\"color: #d4d4d4;\"> = </span><span style=\"color: #9cdcfe;\">currentDateMoment</span><span style=\"color: #d4d4d4;\">.</span><span style=\"color: #dcdcaa;\">diff</span><span style=\"color: #d4d4d4;\">(</span><span style=\"color: #9cdcfe;\">birthDateMoment</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #ce9178;\">\'year\'</span><span style=\"color: #d4d4d4;\">);</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">birthDateMoment</span><span style=\"color: #d4d4d4;\">.</span><span style=\"color: #dcdcaa;\">add</span><span style=\"color: #d4d4d4;\">(</span><span style=\"color: #9cdcfe;\">ageYears</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #ce9178;\">\'years\'</span><span style=\"color: #d4d4d4;\">);</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #569cd6;\">const</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #51b6c4;\">ageMonths</span><span style=\"color: #d4d4d4;\"> = </span><span style=\"color: #9cdcfe;\">currentDateMoment</span><span style=\"color: #d4d4d4;\">.</span><span style=\"color: #dcdcaa;\">diff</span><span style=\"color: #d4d4d4;\">(</span><span style=\"color: #9cdcfe;\">birthDateMoment</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #ce9178;\">\'months\'</span><span style=\"color: #d4d4d4;\">);</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">birthDateMoment</span><span style=\"color: #d4d4d4;\">.</span><span style=\"color: #dcdcaa;\">add</span><span style=\"color: #d4d4d4;\">(</span><span style=\"color: #9cdcfe;\">ageMonths</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #ce9178;\">\'months\'</span><span style=\"color: #d4d4d4;\">);</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #569cd6;\">const</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #51b6c4;\">ageDays</span><span style=\"color: #d4d4d4;\"> = </span><span style=\"color: #9cdcfe;\">currentDateMoment</span><span style=\"color: #d4d4d4;\">.</span><span style=\"color: #dcdcaa;\">diff</span><span style=\"color: #d4d4d4;\">(</span><span style=\"color: #9cdcfe;\">birthDateMoment</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #ce9178;\">\'days\'</span><span style=\"color: #d4d4d4;\">);</span></div><br><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #569cd6;\">const</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #51b6c4;\">isBirthday</span><span style=\"color: #d4d4d4;\"> = (</span><span style=\"color: #9cdcfe;\">birthDateDay</span><span style=\"color: #d4d4d4;\"> === </span><span style=\"color: #9cdcfe;\">day</span><span style=\"color: #d4d4d4;\"> && </span><span style=\"color: #9cdcfe;\">birthDateMonth</span><span style=\"color: #d4d4d4;\"> === </span><span style=\"color: #9cdcfe;\">month</span><span style=\"color: #d4d4d4;\">); </span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #c586c0;\">return</span><span style=\"color: #d4d4d4;\"> { </span><span style=\"color: #9cdcfe;\">ageYears</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #9cdcfe;\">ageMonths</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #9cdcfe;\">ageDays</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #9cdcfe;\">isBirthday</span><span style=\"color: #d4d4d4;\"> };</span></div><div><span style=\"color: #d4d4d4;\">}</span></div></div>', '[{\"name\": \"birthDate\", \"type\": \"calendar\", \"label\": \"Entrez la date de naissance au format (dd/mm/yyyy) :\", \"placeholder\": \"Sélectionnez une date\"}]', 1, '2019-08-16 00:00:00', '2020-05-08 13:39:30', 1),
|
|
(4, 'Conversion de Température', 'convertTemperature', 'Convertis des Degré Celsius en Degré Fahrenheit et l\'inverse aussi.', '/images/functions/convertTemperature.png', 'form', '<p>Cette fonction n\"est pas trop intéressante, c\"est juste de l\"application de formules :</p><div class=\"vscode-editor\" style=\"color: #d4d4d4;background-color: #1e1e1e;font-family: Consolas, \'Courier New\', monospace;font-weight: normal;font-size: 14px;line-height: 19px;white-space: pre;\"><div><span style=\"color: #6a9955;\"> * </span><span style=\"color: #569cd6;\">@description</span><span style=\"color: #6a9955;\"> Convertis des °C en °F et l\'inverse aussi.</span></div><div><span style=\"color: #6a9955;\"> * </span><span style=\"color: #569cd6;\">@param</span><span style=\"color: #6a9955;\"> </span><span style=\"color: #4ec9b0;\">{number}</span><span style=\"color: #6a9955;\"> </span><span style=\"color: #9cdcfe;\">degree</span><span style=\"color: #6a9955;\"> - Nombre de degrès</span></div><div><span style=\"color: #6a9955;\"> * </span><span style=\"color: #569cd6;\">@param</span><span style=\"color: #6a9955;\"> </span><span style=\"color: #4ec9b0;\">{string}</span><span style=\"color: #6a9955;\"> </span><span style=\"color: #9cdcfe;\">unit</span><span style=\"color: #6a9955;\"> - Unité du nombre (°C ou °F) après conversion</span></div><div><span style=\"color: #6a9955;\"> * </span><span style=\"color: #569cd6;\">@returns</span><span style=\"color: #6a9955;\"> </span><span style=\"color: #4ec9b0;\">{object}</span><span style=\"color: #6a9955;\"> le nombre résultat</span></div><div><span style=\"color: #6a9955;\"> * </span><span style=\"color: #569cd6;\">@examples</span><span style=\"color: #6a9955;\"> convertTemperature(23, \'°F\') → 73.4</span></div><div><span style=\"color: #6a9955;\"> */</span></div><div><span style=\"color: #569cd6;\">function</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #dcdcaa;\">convertTemperature</span><span style=\"color: #d4d4d4;\">(</span><span style=\"color: #9cdcfe;\">degree</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #9cdcfe;\">unit</span><span style=\"color: #d4d4d4;\">) {</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #569cd6;\">let</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">temperatureValue</span><span style=\"color: #d4d4d4;\"> = </span><span style=\"color: #b5cea8;\">0</span><span style=\"color: #d4d4d4;\">;</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #c586c0;\">if</span><span style=\"color: #d4d4d4;\"> (</span><span style=\"color: #9cdcfe;\">unit</span><span style=\"color: #d4d4d4;\"> === </span><span style=\"color: #ce9178;\">\"°C\"</span><span style=\"color: #d4d4d4;\">) {</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">temperatureValue</span><span style=\"color: #d4d4d4;\"> = (</span><span style=\"color: #9cdcfe;\">degree</span><span style=\"color: #d4d4d4;\"> - </span><span style=\"color: #b5cea8;\">32</span><span style=\"color: #d4d4d4;\">) * </span><span style=\"color: #b5cea8;\">5</span><span style=\"color: #d4d4d4;\">/</span><span style=\"color: #b5cea8;\">9</span><span style=\"color: #d4d4d4;\">;</span></div><div><span style=\"color: #d4d4d4;\"> }</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #c586c0;\">else</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #c586c0;\">if</span><span style=\"color: #d4d4d4;\"> (</span><span style=\"color: #9cdcfe;\">unit</span><span style=\"color: #d4d4d4;\"> === </span><span style=\"color: #ce9178;\">\"°F\"</span><span style=\"color: #d4d4d4;\">) {</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">temperatureValue</span><span style=\"color: #d4d4d4;\"> = ((</span><span style=\"color: #9cdcfe;\">degree</span><span style=\"color: #d4d4d4;\"> * </span><span style=\"color: #b5cea8;\">9</span><span style=\"color: #d4d4d4;\">/</span><span style=\"color: #b5cea8;\">5</span><span style=\"color: #d4d4d4;\">) + </span><span style=\"color: #b5cea8;\">32</span><span style=\"color: #d4d4d4;\">);</span></div><div><span style=\"color: #d4d4d4;\"> }</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #c586c0;\">return</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">temperatureValue</span><span style=\"color: #d4d4d4;\">;</span></div><div><span style=\"color: #d4d4d4;\">} </span></div></div>', '[{\"name\": \"degree\", \"type\": \"float\", \"label\": \"Entrez la température\", \"placeholder\": \"(e.g : 23)\"}, {\"name\": \"unitToConvert\", \"type\": \"select\", \"label\": \"Convertir en : \", \"options\": [{\"name\": \"Degré Celsius (°C)\", \"value\": \"°C\"}, {\"name\": \"Degré Fahrenheit (°F)\", \"value\": \"°F\"}], \"placeholder\": \"\"}]', 1, '2019-08-16 00:00:00', '2020-05-08 13:34:26', 1),
|
|
(5, 'Conversion de Distance', 'convertDistance', 'Convertis la longueur (distance) avec les unités allant de picomètre au Téramètre.', '/images/functions/convertDistance.png', 'form', '<p>Pour cette fonction on a un tableau de référence allant de pm à Tm :</p><div class=\"vscode-editor\" style=\"color: #d4d4d4;background-color: #1e1e1e;font-family: Consolas, \'Courier New\', monospace;font-weight: normal;font-size: 14px;line-height: 19px;white-space: pre;\"><div><span style=\"color: #569cd6;\">const</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #51b6c4;\">correspondancesDistance</span><span style=\"color: #d4d4d4;\"> = [</span><span style=\"color: #ce9178;\">\"pm\"</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #569cd6;\">null</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #569cd6;\">null</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #ce9178;\">\"nm\"</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #569cd6;\">null</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #569cd6;\">null</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #ce9178;\">\"µm\"</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #569cd6;\">null</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #569cd6;\">null</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #ce9178;\">\"mm\"</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #ce9178;\">\"cm\"</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #ce9178;\">\"dm\"</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #ce9178;\">\"m\"</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #ce9178;\">\"dam\"</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #ce9178;\">\"hm\"</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #ce9178;\">\"km\"</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #569cd6;\">null</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #569cd6;\">null</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #ce9178;\">\"Mm\"</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #569cd6;\">null</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #569cd6;\">null</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #ce9178;\">\"Gm\"</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #569cd6;\">null</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #569cd6;\">null</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #ce9178;\">\"Tm\"</span><span style=\"color: #d4d4d4;\">];</span></div></div><p>Puis grâce à la différence des index des unités, on peut multiplier la valeur initiale par 10 puissance la différence :</p><div class=\"vscode-editor\" style=\"color: #d4d4d4;background-color: #1e1e1e;font-family: Consolas, \'Courier New\', monospace;font-weight: normal;font-size: 14px;line-height: 19px;white-space: pre;\"><div><span style=\"color: #6a9955;\">/** </span></div><div><span style=\"color: #6a9955;\"> * </span><span style=\"color: #569cd6;\">@description</span><span style=\"color: #6a9955;\"> Convertis la longueur (distance) avec les unités allant de picomètre au Téramètre.</span></div><div><span style=\"color: #6a9955;\"> * </span><span style=\"color: #569cd6;\">@param</span><span style=\"color: #6a9955;\"> </span><span style=\"color: #4ec9b0;\">{number}</span><span style=\"color: #6a9955;\"> </span><span style=\"color: #9cdcfe;\">firstValue</span><span style=\"color: #6a9955;\"> - Le nombre que vous voulez convertir</span></div><div><span style=\"color: #6a9955;\"> * </span><span style=\"color: #569cd6;\">@param</span><span style=\"color: #6a9955;\"> </span><span style=\"color: #4ec9b0;\">{string}</span><span style=\"color: #6a9955;\"> </span><span style=\"color: #9cdcfe;\">unitFirstValue</span><span style=\"color: #6a9955;\"> - L\'unité du nombre que vous voulez convertir</span></div><div><span style=\"color: #6a9955;\"> * </span><span style=\"color: #569cd6;\">@param</span><span style=\"color: #6a9955;\"> </span><span style=\"color: #4ec9b0;\">{string}</span><span style=\"color: #6a9955;\"> </span><span style=\"color: #9cdcfe;\">unitFinalValue</span><span style=\"color: #6a9955;\"> - L\'unité de votre nombre après la conversion</span></div><div><span style=\"color: #6a9955;\"> * </span><span style=\"color: #569cd6;\">@returns</span><span style=\"color: #6a9955;\"> </span><span style=\"color: #4ec9b0;\">{number}</span><span style=\"color: #6a9955;\"> → le nombre résultat</span></div><div><span style=\"color: #6a9955;\"> * </span><span style=\"color: #569cd6;\">@examples</span><span style=\"color: #6a9955;\"> convertDistance(500, \'cm\', \'m\') → 5</span></div><div><span style=\"color: #6a9955;\"> */</span></div><div><span style=\"color: #569cd6;\">function</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #dcdcaa;\">convertDistance</span><span style=\"color: #d4d4d4;\">(</span><span style=\"color: #9cdcfe;\">firstValue</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #9cdcfe;\">unitFirstValue</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #9cdcfe;\">unitFinalValue</span><span style=\"color: #d4d4d4;\">) {</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #569cd6;\">const</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #51b6c4;\">index1</span><span style=\"color: #d4d4d4;\"> = </span><span style=\"color: #9cdcfe;\">correspondancesDistance</span><span style=\"color: #d4d4d4;\">.</span><span style=\"color: #dcdcaa;\">indexOf</span><span style=\"color: #d4d4d4;\">(</span><span style=\"color: #9cdcfe;\">unitFirstValue</span><span style=\"color: #d4d4d4;\">); </span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #569cd6;\">const</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #51b6c4;\">index2</span><span style=\"color: #d4d4d4;\"> = </span><span style=\"color: #9cdcfe;\">correspondancesDistance</span><span style=\"color: #d4d4d4;\">.</span><span style=\"color: #dcdcaa;\">indexOf</span><span style=\"color: #d4d4d4;\">(</span><span style=\"color: #9cdcfe;\">unitFinalValue</span><span style=\"color: #d4d4d4;\">);</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #569cd6;\">const</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #51b6c4;\">difference</span><span style=\"color: #d4d4d4;\"> = </span><span style=\"color: #9cdcfe;\">index1</span><span style=\"color: #d4d4d4;\"> - </span><span style=\"color: #9cdcfe;\">index2</span><span style=\"color: #d4d4d4;\">; </span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #c586c0;\">return</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">firstValue</span><span style=\"color: #d4d4d4;\"> * </span><span style=\"color: #4ec9b0;\">Math</span><span style=\"color: #d4d4d4;\">.</span><span style=\"color: #dcdcaa;\">pow</span><span style=\"color: #d4d4d4;\">(</span><span style=\"color: #b5cea8;\">10</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #9cdcfe;\">difference</span><span style=\"color: #d4d4d4;\">);</span></div><div><span style=\"color: #d4d4d4;\">}</span></div></div>', '[{\"name\": \"number\", \"type\": \"float\", \"label\": \"Entrez la distance que vous voulez convertir :\", \"placeholder\": \"(e.g : 50)\"}, {\"name\": \"numberUnit\", \"type\": \"select\", \"label\": \"L\'unité du nombre que vous voulez convertir : \", \"options\": [{\"name\": \"Picomètre (pm)\", \"value\": \"pm\"}, {\"name\": \"Nanomètre (nm)\", \"value\": \"nm\"}, {\"name\": \"Micromètre (µm)\", \"value\": \"µm\"}, {\"name\": \"Millimètre (mm)\", \"value\": \"mm\"}, {\"name\": \"Centimètre (cm)\", \"value\": \"cm\"}, {\"name\": \"Décimètre (dm)\", \"value\": \"dm\"}, {\"name\": \"Mètre (m)\", \"value\": \"m\"}, {\"name\": \"Décamètre (dam)\", \"value\": \"dam\"}, {\"name\": \"Hectomètre (hm)\", \"value\": \"hm\"}, {\"name\": \"Kilomètre (km)\", \"value\": \"km\"}, {\"name\": \"Mégamètre (Mm)\", \"value\": \"Mm\"}, {\"name\": \"Gigamètre (Gm)\", \"value\": \"Gm\"}, {\"name\": \"Téramètre (Tm)\", \"value\": \"Tm\"}], \"placeholder\": \"\"}, {\"name\": \"finalUnit\", \"type\": \"select\", \"label\": \"Choisissez l\'unité que vous voulez avoir après conversion :\", \"options\": [{\"name\": \"Picomètre (pm)\", \"value\": \"pm\"}, {\"name\": \"Nanomètre (nm)\", \"value\": \"nm\"}, {\"name\": \"Micromètre (µm)\", \"value\": \"µm\"}, {\"name\": \"Millimètre (mm)\", \"value\": \"mm\"}, {\"name\": \"Centimètre (cm)\", \"value\": \"cm\"}, {\"name\": \"Décimètre (dm)\", \"value\": \"dm\"}, {\"name\": \"Mètre (m)\", \"value\": \"m\"}, {\"name\": \"Décamètre (dam)\", \"value\": \"dam\"}, {\"name\": \"Hectomètre (hm)\", \"value\": \"hm\"}, {\"name\": \"Kilomètre (km)\", \"value\": \"km\"}, {\"name\": \"Mégamètre (Mm)\", \"value\": \"Mm\"}, {\"name\": \"Gigamètre (Gm)\", \"value\": \"Gm\"}, {\"name\": \"Téramètre (Tm)\", \"value\": \"Tm\"}], \"placeholder\": \"\"}]', 1, '2019-08-16 00:00:00', '2020-05-08 13:30:46', 1),
|
|
(6, 'Générateur de citations', 'randomQuote', 'Génère aléatoirement une citation ou un proverbe.', '/images/functions/randomQuote.png', 'page', '<p>Même principe que la fonction randomNumber, on a une liste de citation contenu dans un tableau et on sélectionne un index au hasard dans ce tableau grâce à la fonction randomNumber, par exemple :</p><div class=\"vscode-editor\" style=\"color: #d4d4d4;background-color: #1e1e1e;font-family: Consolas, \'Courier New\', monospace;font-weight: normal;font-size: 14px;line-height: 19px;white-space: pre;\"><div><span style=\"color: #569cd6;\">function</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #dcdcaa;\">randomNumber</span><span style=\"color: #d4d4d4;\">(</span><span style=\"color: #9cdcfe;\">min</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #9cdcfe;\">max</span><span style=\"color: #d4d4d4;\">) {</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #c586c0;\">return</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #4ec9b0;\">Math</span><span style=\"color: #d4d4d4;\">.</span><span style=\"color: #dcdcaa;\">floor</span><span style=\"color: #d4d4d4;\">(</span><span style=\"color: #4ec9b0;\">Math</span><span style=\"color: #d4d4d4;\">.</span><span style=\"color: #dcdcaa;\">random</span><span style=\"color: #d4d4d4;\">() * (</span><span style=\"color: #9cdcfe;\">max</span><span style=\"color: #d4d4d4;\"> - </span><span style=\"color: #9cdcfe;\">min</span><span style=\"color: #d4d4d4;\"> +</span><span style=\"color: #b5cea8;\">1</span><span style=\"color: #d4d4d4;\">)) + </span><span style=\"color: #9cdcfe;\">min</span><span style=\"color: #d4d4d4;\">;</span></div><div><span style=\"color: #d4d4d4;\">}</span></div><div><span style=\"color: #569cd6;\">const</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #51b6c4;\">quotes</span><span style=\"color: #d4d4d4;\"> = [</span></div><div><span style=\"color: #d4d4d4;\"> {</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">quote:</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #ce9178;\">\"Deux choses sont infinies: l\'univers et la bêtise humaine; et je ne suis pas sûr de l\'univers.\"</span><span style=\"color: #d4d4d4;\">,</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">source:</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #ce9178;\">\"Albert Einstein\"</span></div><div><span style=\"color: #d4d4d4;\"> },</span></div><div><span style=\"color: #d4d4d4;\"> {</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">quote:</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #ce9178;\">\"Exige beaucoup de toi-même et attends peu des autres. Ainsi beaucoup d\'ennuis te seront épargnés.\"</span><span style=\"color: #d4d4d4;\">,</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">source:</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #ce9178;\">\"Confucius\"</span></div><div><span style=\"color: #d4d4d4;\"> }</span></div><div><span style=\"color: #d4d4d4;\">];</span></div><div><span style=\"color: #4ec9b0;\">console</span><span style=\"color: #d4d4d4;\">.</span><span style=\"color: #dcdcaa;\">log</span><span style=\"color: #d4d4d4;\">(</span><span style=\"color: #9cdcfe;\">quotes</span><span style=\"color: #d4d4d4;\">[</span><span style=\"color: #dcdcaa;\">randomNumber</span><span style=\"color: #d4d4d4;\">(</span><span style=\"color: #b5cea8;\">0</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #9cdcfe;\">quotes</span><span style=\"color: #d4d4d4;\">.</span><span style=\"color: #9cdcfe;\">length</span><span style=\"color: #d4d4d4;\"> - </span><span style=\"color: #b5cea8;\">1</span><span style=\"color: #d4d4d4;\">)]);</span></div></div>', NULL, 1, '2019-09-13 00:00:00', '2020-05-08 13:52:57', 1),
|
|
(7, 'Conversion de devise', 'convertCurrency', 'Convertis une valeur dans une devise dans une autre devise.', '/images/functions/convertCurrency.png', 'form', '<p>Les taux de changes sont récupérée grâce à l\"api : <a target=\"_blank\" href=\"https://api.exchangeratesapi.io\">https://api.exchangeratesapi.io</a></p><p>Pas plus compliqué qu\'une simple requête GET.</p>', '[{\"name\": \"number\", \"type\": \"float\", \"label\": \"Entrez le nombre à convertir :\", \"placeholder\": \"(e.g : 50)\"}, {\"name\": \"baseCurrency\", \"type\": \"select\", \"label\": \"La devise du nombre que vous voulez convertir :\", \"options\": [{\"name\": \"Euro (€) - EUR\", \"value\": \"EUR\"}, {\"name\": \"Livre sterling (£) - GBP\", \"value\": \"GBP\"}, {\"name\": \"Dollar Américain ($) - USD\", \"value\": \"USD\"}, {\"name\": \"Dollar Canadien ($) - CAD\", \"value\": \"CAD\"}, {\"name\": \"Dollar Australien ($) - AUD\", \"value\": \"AUD\"}, {\"name\": \"Peso Mexicain ($) - MXN\", \"value\": \"MXN\"}, {\"name\": \"Franc Suisse (Fr) - CHF\", \"value\": \"CHF\"}, {\"name\": \"Rouble Russe (₽) - RUB\", \"value\": \"RUB\"}, {\"name\": \"Réal brésilien (R$) - BRL\", \"value\": \"BRL\"}, {\"name\": \"Yen (¥) - JPY\", \"value\": \"JPY\"}]}, {\"name\": \"finalCurrency\", \"type\": \"select\", \"label\": \"Choisissez la devise que voulez avoir après conversion :\", \"options\": [{\"name\": \"Livre sterling (£) - GBP\", \"value\": \"GBP\"}, {\"name\": \"Dollar Américain ($) - USD\", \"value\": \"USD\"}, {\"name\": \"Dollar Canadien ($) - CAD\", \"value\": \"CAD\"}, {\"name\": \"Dollar Australien ($) - AUD\", \"value\": \"AUD\"}, {\"name\": \"Peso Mexicain ($) - MXN\", \"value\": \"MXN\"}, {\"name\": \"Franc Suisse (Fr) - CHF\", \"value\": \"CHF\"}, {\"name\": \"Rouble Russe (₽) - RUB\", \"value\": \"RUB\"}, {\"name\": \"Réal brésilien (R$) - BRL\", \"value\": \"BRL\"}, {\"name\": \"Yen (¥) - JPY\", \"value\": \"JPY\"}, {\"name\": \"Euro (€) - EUR\", \"value\": \"EUR\"}]}]', 1, '2019-09-13 00:00:00', '2020-05-08 13:47:42', 1),
|
|
(8, 'Conversion des Encodages de caractères', 'convertEncoding', 'Convertis des nombres de différentes bases et convertis en UTF-8.', '/images/functions/convertEncoding.png', 'form', NULL, '[{\"name\": \"value\", \"type\": \"text\", \"label\": \"Entrez votre valeur :\", \"placeholder\": \"Votre valeur...\"}, {\"name\": \"functionName\", \"type\": \"select\", \"label\": \"Choisissez une option :\", \"options\": [{\"name\": \"Décimal en Binaire\", \"value\": \"decimalToBinary\"}, {\"name\": \"Binaire en Décimal\", \"value\": \"binaryToDecimal\"}, {\"name\": \"Décimal en Hexadecimal\", \"value\": \"decimalToHexadecimal\"}, {\"name\": \"Hexadecimal en Décimal\", \"value\": \"hexadecimalToDecimal\"}, {\"name\": \"Binaire en Hexadécimal\", \"value\": \"binaryToHexadecimal\"}, {\"name\": \"Hexadécimal en Binaire\", \"value\": \"hexadecimalToBinary\"}, {\"name\": \"Chaque caractère a un nombre Unicode\", \"value\": \"textToNumberUnicode\"}, {\"name\": \"Chaque nombre Unicode a un caractère\", \"value\": \"numberUnicodeToText\"}, {\"name\": \"Texte en Binaire (UTF-8)\", \"value\": \"textToBinary\"}, {\"name\": \"Binaire (UTF-8) en Texte\", \"value\": \"binaryToText\"}, {\"name\": \"Texte en Hexadécimal (UTF-8)\", \"value\": \"textToHexadecimal\"}, {\"name\": \"Hexadécimal (UTF-8) en Texte\", \"value\": \"hexadecimalToText\"}], \"placeholder\": \"\"}]', 1, '2019-09-14 00:00:00', '2020-04-22 22:34:48', 2),
|
|
(9, 'Conversion d\'un nombre arabe en nombre romain', 'convertRomanArabicNumbers', 'Convertis un nombre arabe en nombre romain (et l\'inverse aussi).', '/images/functions/convertRomanArabicNumbers.png', 'form', NULL, '[{\"name\": \"value\", \"type\": \"text\", \"label\": \"Entrez votre nombre :\", \"placeholder\": \"(e.g : 50 ou L)\"}, {\"name\": \"functionName\", \"type\": \"select\", \"label\": \"Convertir en :\", \"options\": [{\"name\": \"Nombre Romain\", \"value\": \"convertArabicToRomanOutput\"}, {\"name\": \"Nombre Arabe\", \"value\": \"convertRomanToArabicOutput\"}], \"placeholder\": \"\"}]', 1, '2019-09-21 00:00:00', '2020-04-22 22:43:50', 2),
|
|
(10, 'Nombre d\'Armstrong', 'armstrongNumber', 'Permet de savoir si un nombre fait partie des nombres d\'Armstrong.', '/images/functions/armstrongNumber.png', 'form', NULL, '[{\"name\": \"number\", \"type\": \"integer\", \"label\": \"Entrez votre nombre :\", \"placeholder\": \"(e.g : 153)\"}]', 1, '2019-09-21 00:00:00', '2020-04-22 22:49:21', 2),
|
|
(11, 'Heap\'s algorithm', 'heapAlgorithm', 'Génère toutes les permutations uniques possibles d\'une chaîne de caractère.', '/images/functions/heapAlgorithm.png', 'form', NULL, '[{\"name\": \"string\", \"type\": \"text\", \"label\": \"Entrez un mot :\", \"placeholder\": \"(e.g : Mot)\"}]', 1, '2019-10-11 00:01:00', '2020-04-22 23:06:15', 2),
|
|
(12, 'Raccourcisseurs de liens', 'linkShortener', 'Une URL trop longue ? Raccourcissez-là !', '/images/functions/linkShortener.png', 'form', NULL, '[{\"name\": \"url\", \"type\": \"text\", \"label\": \"Entrez le lien à raccourcir :\", \"placeholder\": \"(e.g : https://divlo.fr)\"}, {\"name\": \"shortcutName\", \"type\": \"text\", \"label\": \"Entrez le nom du raccourci :\", \"placeholder\": \"(e.g : divlo)\"}]', 1, '2019-12-11 00:00:00', '2020-04-27 16:31:38', 1),
|
|
(13, 'Liste de choses à faire', 'toDoList', 'Prévoyez la liste de choses que vous devez faire.', '/images/functions/toDoList.png', 'page', NULL, NULL, 1, '2019-12-26 00:00:00', '2020-04-27 16:34:34', 1),
|
|
(14, 'Juste Prix', 'rightPrice', 'Arriverez-vous à deviner le prix d\'un objet ?', '/images/functions/rightPrice.png', 'page', NULL, NULL, 1, '2020-04-27 20:17:05', '2020-04-27 21:59:22', 3),
|
|
(15, 'Chronomètre', 'chronometerTimer', 'Gérer votre temps facilement (et adopter la technique Pomodoro).', '/images/functions/chronometerTimer.png', 'page', NULL, NULL, 1, '2020-04-29 09:28:08', '2020-04-29 09:45:29', 1);
|
|
INSERT INTO `functions` (`id`, `title`, `slug`, `description`, `image`, `type`, `article`, `utilizationForm`, `isOnline`, `createdAt`, `updatedAt`, `categorieId`) VALUES
|
|
(16, 'Les méthodes des tableaux', 'arrayMethods', 'Et si on refaisait les méthodes natives de l\'objet global \"Array\" ?', '/images/functions/arrayMethods.png', 'article', '<p><strong>JavaScript</strong> est un langage <strong>orienté objet</strong>, chaque type comme \"String\", \"Number\", ... sont en réalité des objets. <br>\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nCe sont des \"<a target=\"_blank\" href=\"https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux\">Objets globaux</a>\", qui dispose de méthodes bien utiles. 😎 Pourquoi je vous dit ça ?<br>\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nCar aujourd\"hui nous allons reproduire les méthodes de l\"objet global \"<a target=\"_blank\" href=\"https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/Array\">Array</a>\", c\"est un bon exercice pour progresser.<br>\n<br>\n\n\n\n\n\n\n\n\n\n\n\nNous allons réaliser une classe (syntaxe ES6+) qu\"on va appeler \"DivloArray\" par exemple et reproduire 6 méthodes (push, forEach, map, filter, reverse et join), bien évidemment libre à vous d\"en faire plus. 😊 Je vais expliquer le code une méthode après l\"autre donc bout de code par bout de code, si vous voulez avoir le code source complet, il est disponible sur ce <a target=\"_blank\" href=\"https://gist.github.com/Divlo/4ffc8ed007d293372ee449d2647fcad9\">GitHub Gist.</a><br>\n<br>\n\n\n\n\n\n\n\n\n\n\nDonc tout d\"abord, nous devons créer la classe avec un constructor et faire une nouvelle instance de cet objet dans une variable :<br>\n\n\n\n\n\n\n\n\n(Libre à vous de renommer les variables comme bon vous semble.) <br>\n</p><div class=\"vscode-editor\" style=\"color: #d4d4d4;background-color: #1e1e1e;font-family: Consolas, \'Courier New\', monospace;font-weight: normal;font-size: 14px;line-height: 19px;white-space: pre;\"><div><span style=\"color: #569cd6;\">class</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #4ec9b0;\">DivloArray</span><span style=\"color: #d4d4d4;\"> {</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #569cd6;\">constructor</span><span style=\"color: #d4d4d4;\">(</span><span style=\"color: #9cdcfe;\">array</span><span style=\"color: #d4d4d4;\">) {</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #569cd6;\">this</span><span style=\"color: #d4d4d4;\">.</span><span style=\"color: #9cdcfe;\">array</span><span style=\"color: #d4d4d4;\"> = </span><span style=\"color: #9cdcfe;\">array</span><span style=\"color: #d4d4d4;\">;</span></div><div><span style=\"color: #d4d4d4;\"> }</span></div><div><span style=\"color: #d4d4d4;\">}</span></div><br>\n\n<div><span style=\"color: #569cd6;\">const</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">divloArray</span><span style=\"color: #d4d4d4;\"> = </span><span style=\"color: #569cd6;\">new</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #4ec9b0;\">DivloArray</span><span style=\"color: #d4d4d4;\">([</span><span style=\"color: #b5cea8;\">57</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #b5cea8;\">4</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #b5cea8;\">2</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #b5cea8;\">8</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #b5cea8;\">16</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #b5cea8;\">25</span><span style=\"color: #d4d4d4;\">]);</span></div></div><p><br>\n\n\n\n\n\n\n- Nous allons commencer par créer la première méthode très utilisée qui consiste à ajouter un ou plusieurs éléments à la fin d\"un tableau, je parle bien évidemment de la méthode <strong>push</strong>.</p><div class=\"vscode-editor\" style=\"color: #d4d4d4;background-color: #1e1e1e;font-family: Consolas, \'Courier New\', monospace;font-weight: normal;font-size: 14px;line-height: 19px;white-space: pre;\"><div><span style=\"color: #6a9955;\">/**</span></div><div><span style=\"color: #6a9955;\"> * </span><span style=\"color: #569cd6;\">@description</span><span style=\"color: #6a9955;\"> Ajoute un ou plusieurs éléments à la fin d\"un tableau et retourne la nouvelle taille du tableau.</span></div><div><span style=\"color: #6a9955;\"> * </span><span style=\"color: #569cd6;\">@param</span><span style=\"color: #6a9955;\"> </span><span style=\"color: #4ec9b0;\">{*}</span><span style=\"color: #6a9955;\"> </span><span style=\"color: #9cdcfe;\">elements</span><span style=\"color: #6a9955;\"> Éléments à ajoutés</span></div><div><span style=\"color: #6a9955;\"> * </span><span style=\"color: #569cd6;\">@returns</span><span style=\"color: #6a9955;\"> </span><span style=\"color: #4ec9b0;\">{Number}</span><span style=\"color: #6a9955;\"> La taille (length) du nouveau tableau</span></div><div><span style=\"color: #6a9955;\"> */</span></div><div><span style=\"color: #dcdcaa;\">push</span><span style=\"color: #d4d4d4;\">(...</span><span style=\"color: #9cdcfe;\">elements</span><span style=\"color: #d4d4d4;\">) {</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #569cd6;\">let</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">indexCourant</span><span style=\"color: #d4d4d4;\"> = </span><span style=\"color: #569cd6;\">this</span><span style=\"color: #d4d4d4;\">.</span><span style=\"color: #9cdcfe;\">array</span><span style=\"color: #d4d4d4;\">.</span><span style=\"color: #9cdcfe;\">length</span><span style=\"color: #d4d4d4;\">;</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">elements</span><span style=\"color: #d4d4d4;\">.</span><span style=\"color: #dcdcaa;\">forEach</span><span style=\"color: #d4d4d4;\">((</span><span style=\"color: #9cdcfe;\">element</span><span style=\"color: #d4d4d4;\">) </span><span style=\"color: #569cd6;\">=></span><span style=\"color: #d4d4d4;\"> {</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #569cd6;\">this</span><span style=\"color: #d4d4d4;\">.</span><span style=\"color: #9cdcfe;\">array</span><span style=\"color: #d4d4d4;\">[</span><span style=\"color: #9cdcfe;\">indexCourant</span><span style=\"color: #d4d4d4;\">] = </span><span style=\"color: #9cdcfe;\">element</span><span style=\"color: #d4d4d4;\">;</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">indexCourant</span><span style=\"color: #d4d4d4;\">++;</span></div><div><span style=\"color: #d4d4d4;\"> });</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #c586c0;\">return</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #569cd6;\">this</span><span style=\"color: #d4d4d4;\">.</span><span style=\"color: #9cdcfe;\">array</span><span style=\"color: #d4d4d4;\">.</span><span style=\"color: #9cdcfe;\">length</span><span style=\"color: #d4d4d4;\">;</span></div><div><span style=\"color: #d4d4d4;\">}</span></div></div><p>Alors on prend en paramètre des éléments avec le spread operator ce qui nous permet d\"obtenir un tableau (exemple: 1, 2, 3 devient [1, 2, 3]). On fait une variable indexCourant qui est égale à la taille du tableau qu\"on incrémentera de 1 à chaque tour de boucle, comme ça on peut accéder à l\"index qui n\"existe pas encore et lui attribuer une valeur, l\"élement en cours de la boucle, si vous avez des questions n\"hésitez pas à les poster en commentaire.<br>\n<br>\n\n\n\n\n\n\n- La méthode <strong>forEach : </strong></p><div class=\"vscode-editor\" style=\"color: #d4d4d4;background-color: #1e1e1e;font-family: Consolas, \'Courier New\', monospace;font-weight: normal;font-size: 14px;line-height: 19px;white-space: pre;\"><div><span style=\"color: #6a9955;\">/**</span></div><div><span style=\"color: #6a9955;\"> * </span><span style=\"color: #569cd6;\">@description</span><span style=\"color: #6a9955;\"> Permet d\"exécuter une fonction donnée sur chaque élément du tableau. </span></div><div><span style=\"color: #6a9955;\"> * </span><span style=\"color: #569cd6;\">@param</span><span style=\"color: #6a9955;\"> </span><span style=\"color: #4ec9b0;\">{Function}</span><span style=\"color: #6a9955;\"> </span><span style=\"color: #9cdcfe;\">callback</span><span style=\"color: #6a9955;\"> Une fonction qui accepte jusqu\"à trois arguments :</span></div><div><span style=\"color: #6a9955;\"> * - valeurCourante → La valeur de l\"élément du tableau en cours de traitement.</span></div><div><span style=\"color: #6a9955;\"> * - index → L\"indice de l\"élément du tableau en cours de traitement.</span></div><div><span style=\"color: #6a9955;\"> * - array → Le tableau sur lequel la méthode forEach est appliquée.</span></div><div><span style=\"color: #6a9955;\"> */</span></div><div><span style=\"color: #dcdcaa;\">forEach</span><span style=\"color: #d4d4d4;\">(</span><span style=\"color: #9cdcfe;\">callback</span><span style=\"color: #d4d4d4;\">) {</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #c586c0;\">for</span><span style=\"color: #d4d4d4;\"> (</span><span style=\"color: #569cd6;\">let</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">index</span><span style=\"color: #d4d4d4;\"> = </span><span style=\"color: #b5cea8;\">0</span><span style=\"color: #d4d4d4;\">; </span><span style=\"color: #9cdcfe;\">index</span><span style=\"color: #d4d4d4;\"> < </span><span style=\"color: #569cd6;\">this</span><span style=\"color: #d4d4d4;\">.</span><span style=\"color: #9cdcfe;\">array</span><span style=\"color: #d4d4d4;\">.</span><span style=\"color: #9cdcfe;\">length</span><span style=\"color: #d4d4d4;\">; </span><span style=\"color: #9cdcfe;\">index</span><span style=\"color: #d4d4d4;\">++) {</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #569cd6;\">const</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">valeurCourante</span><span style=\"color: #d4d4d4;\"> = </span><span style=\"color: #569cd6;\">this</span><span style=\"color: #d4d4d4;\">.</span><span style=\"color: #9cdcfe;\">array</span><span style=\"color: #d4d4d4;\">[</span><span style=\"color: #9cdcfe;\">index</span><span style=\"color: #d4d4d4;\">];</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #dcdcaa;\">callback</span><span style=\"color: #d4d4d4;\">(</span><span style=\"color: #9cdcfe;\">valeurCourante</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #9cdcfe;\">index</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #569cd6;\">this</span><span style=\"color: #d4d4d4;\">.</span><span style=\"color: #9cdcfe;\">array</span><span style=\"color: #d4d4d4;\">);</span></div><div><span style=\"color: #d4d4d4;\"> }</span></div><div><span style=\"color: #d4d4d4;\">}</span></div></div><p>Prend une fonction callback, c\"est à dire une fonction qui va être exécutée dans le corps de la fonction et on fait une simple boucle for.<br>\n<br>\n\n\n\n\n\n- La méthode <strong>map</strong> :</p><div class=\"vscode-editor\" style=\"color: #d4d4d4;background-color: #1e1e1e;font-family: Consolas, \'Courier New\', monospace;font-weight: normal;font-size: 14px;line-height: 19px;white-space: pre;\"><div><span style=\"color: #6a9955;\">/**</span></div><div><span style=\"color: #6a9955;\"> * </span><span style=\"color: #569cd6;\">@description</span><span style=\"color: #6a9955;\"> Crée un nouveau tableau avec les résultats de l\"appel d\"une fonction fournie sur chaque élément du tableau appelant.</span></div><div><span style=\"color: #6a9955;\"> * </span><span style=\"color: #569cd6;\">@param</span><span style=\"color: #6a9955;\"> </span><span style=\"color: #4ec9b0;\">{Function}</span><span style=\"color: #6a9955;\"> </span><span style=\"color: #9cdcfe;\">callback</span><span style=\"color: #6a9955;\"> Une fonction qui accepte jusqu\"à trois arguments.</span></div><div><span style=\"color: #6a9955;\"> * - valeurCourante → La valeur de l\"élément du tableau en cours de traitement.</span></div><div><span style=\"color: #6a9955;\"> * - index → L\"indice de l\"élément du tableau en cours de traitement.</span></div><div><span style=\"color: #6a9955;\"> * - array → Le tableau sur lequel la méthode est appliquée.</span></div><div><span style=\"color: #6a9955;\"> * </span><span style=\"color: #569cd6;\">@returns</span><span style=\"color: #6a9955;\"> </span><span style=\"color: #4ec9b0;\">{Array}</span><span style=\"color: #6a9955;\"> Un nouveau tableau composé des images de la fonction de rappel.</span></div><div><span style=\"color: #6a9955;\"> */</span></div><div><span style=\"color: #dcdcaa;\">map</span><span style=\"color: #d4d4d4;\">(</span><span style=\"color: #9cdcfe;\">callback</span><span style=\"color: #d4d4d4;\">) {</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #569cd6;\">const</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">array</span><span style=\"color: #d4d4d4;\"> = [...</span><span style=\"color: #569cd6;\">this</span><span style=\"color: #d4d4d4;\">.</span><span style=\"color: #9cdcfe;\">array</span><span style=\"color: #d4d4d4;\">]; </span><span style=\"color: #6a9955;\">// permet de ne pas changer les valeurs du tableau original (car passage par référence)</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #569cd6;\">this</span><span style=\"color: #d4d4d4;\">.</span><span style=\"color: #dcdcaa;\">forEach</span><span style=\"color: #d4d4d4;\">((</span><span style=\"color: #9cdcfe;\">elementCourant</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #9cdcfe;\">indexCourant</span><span style=\"color: #d4d4d4;\">) </span><span style=\"color: #569cd6;\">=></span><span style=\"color: #d4d4d4;\"> {</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">array</span><span style=\"color: #d4d4d4;\">[</span><span style=\"color: #9cdcfe;\">indexCourant</span><span style=\"color: #d4d4d4;\">] = </span><span style=\"color: #dcdcaa;\">callback</span><span style=\"color: #d4d4d4;\">(</span><span style=\"color: #9cdcfe;\">elementCourant</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #9cdcfe;\">indexCourant</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #569cd6;\">this</span><span style=\"color: #d4d4d4;\">.</span><span style=\"color: #9cdcfe;\">array</span><span style=\"color: #d4d4d4;\">);</span></div><div><span style=\"color: #d4d4d4;\"> });</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #c586c0;\">return</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">array</span><span style=\"color: #d4d4d4;\">;</span></div><div><span style=\"color: #d4d4d4;\">}</span></div></div><p><br>\n\n\n\n\n- La méthode <strong>filter</strong> : </p><div class=\"vscode-editor\" style=\"color: #d4d4d4;background-color: #1e1e1e;font-family: Consolas, \'Courier New\', monospace;font-weight: normal;font-size: 14px;line-height: 19px;white-space: pre;\"><div><span style=\"color: #6a9955;\">/**</span></div><div><span style=\"color: #6a9955;\"> * </span><span style=\"color: #569cd6;\">@description</span><span style=\"color: #6a9955;\"> Retourne un nouveau tableau contenant tous les éléments du tableau d\"origine qui remplissent une condition déterminée par la fonction callback.</span></div><div><span style=\"color: #6a9955;\"> * </span><span style=\"color: #569cd6;\">@param</span><span style=\"color: #6a9955;\"> </span><span style=\"color: #4ec9b0;\">{Function}</span><span style=\"color: #6a9955;\"> </span><span style=\"color: #9cdcfe;\">callback</span><span style=\"color: #6a9955;\"> La fonction de test à appliquer à chaque élément du tableau. Cette fonction est appelée avec les arguments suivants :</span></div><div><span style=\"color: #6a9955;\"> * - elementCourant → L\"élément à traiter</span></div><div><span style=\"color: #6a9955;\"> * - index → Son indice</span></div><div><span style=\"color: #6a9955;\"> * - array → Le tableau complet</span></div><div><span style=\"color: #6a9955;\"> * </span><span style=\"color: #569cd6;\">@returns</span><span style=\"color: #6a9955;\"> </span><span style=\"color: #4ec9b0;\">{Array}</span><span style=\"color: #6a9955;\"> Un nouveau tableau contenant les éléments qui respectent la condition du filtre. Si aucun élément ne respecte la condition, c\"est un tableau vide qui est renvoyé.</span></div><div><span style=\"color: #6a9955;\"> */</span></div><div><span style=\"color: #dcdcaa;\">filter</span><span style=\"color: #d4d4d4;\">(</span><span style=\"color: #9cdcfe;\">callback</span><span style=\"color: #d4d4d4;\">) {</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #569cd6;\">const</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">resultArray</span><span style=\"color: #d4d4d4;\"> = [];</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #569cd6;\">this</span><span style=\"color: #d4d4d4;\">.</span><span style=\"color: #dcdcaa;\">forEach</span><span style=\"color: #d4d4d4;\">((</span><span style=\"color: #9cdcfe;\">elementCourant</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #9cdcfe;\">indexCourant</span><span style=\"color: #d4d4d4;\">) </span><span style=\"color: #569cd6;\">=></span><span style=\"color: #d4d4d4;\"> {</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #569cd6;\">const</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">isTrue</span><span style=\"color: #d4d4d4;\"> = </span><span style=\"color: #dcdcaa;\">callback</span><span style=\"color: #d4d4d4;\">(</span><span style=\"color: #9cdcfe;\">elementCourant</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #9cdcfe;\">indexCourant</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #569cd6;\">this</span><span style=\"color: #d4d4d4;\">.</span><span style=\"color: #9cdcfe;\">array</span><span style=\"color: #d4d4d4;\">);</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #c586c0;\">if</span><span style=\"color: #d4d4d4;\"> (</span><span style=\"color: #9cdcfe;\">isTrue</span><span style=\"color: #d4d4d4;\">) {</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">resultArray</span><span style=\"color: #d4d4d4;\">.</span><span style=\"color: #dcdcaa;\">push</span><span style=\"color: #d4d4d4;\">(</span><span style=\"color: #9cdcfe;\">elementCourant</span><span style=\"color: #d4d4d4;\">);</span></div><div><span style=\"color: #d4d4d4;\"> }</span></div><div><span style=\"color: #d4d4d4;\"> });</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #c586c0;\">return</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">resultArray</span><span style=\"color: #d4d4d4;\">;</span></div><div><span style=\"color: #d4d4d4;\">}</span></div></div><p>Comme on peut le voir beaucoup de ces méthodes recoivent une fonction callback, en tout cas, cette méthode ressemble beaucoup à la méthode map sauf que cette fois çi à la place de faire une assignation on vérifie si la callback nous renvoie True et si oui on push l\"élément à notre tableau de résultats.<br>\n<br>\n\n\n- La méthode <strong>reverse</strong> qui inverse le tableau : </p><div class=\"vscode-editor\" style=\"color: #d4d4d4;background-color: #1e1e1e;font-family: Consolas, \'Courier New\', monospace;font-weight: normal;font-size: 14px;line-height: 19px;white-space: pre;\"><div><span style=\"color: #6a9955;\">/**</span></div><div><span style=\"color: #6a9955;\"> * </span><span style=\"color: #569cd6;\">@description</span><span style=\"color: #6a9955;\"> Transpose les éléments d\"un tableau : le premier élément devient le dernier et le dernier devient le premier et ainsi de suite.</span></div><div><span style=\"color: #6a9955;\"> * </span><span style=\"color: #569cd6;\">@returns</span><span style=\"color: #6a9955;\"> </span><span style=\"color: #4ec9b0;\">{Array}</span><span style=\"color: #6a9955;\"> Le tableau inversé</span></div><div><span style=\"color: #6a9955;\"> */</span></div><div><span style=\"color: #dcdcaa;\">reverse</span><span style=\"color: #d4d4d4;\">() {</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #569cd6;\">const</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">reverseArray</span><span style=\"color: #d4d4d4;\"> = [];</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #c586c0;\">for</span><span style=\"color: #d4d4d4;\"> (</span><span style=\"color: #569cd6;\">let</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">index</span><span style=\"color: #d4d4d4;\"> = </span><span style=\"color: #569cd6;\">this</span><span style=\"color: #d4d4d4;\">.</span><span style=\"color: #9cdcfe;\">array</span><span style=\"color: #d4d4d4;\">.</span><span style=\"color: #9cdcfe;\">length</span><span style=\"color: #d4d4d4;\"> - </span><span style=\"color: #b5cea8;\">1</span><span style=\"color: #d4d4d4;\">; </span><span style=\"color: #9cdcfe;\">index</span><span style=\"color: #d4d4d4;\"> >= </span><span style=\"color: #b5cea8;\">0</span><span style=\"color: #d4d4d4;\">; </span><span style=\"color: #9cdcfe;\">index</span><span style=\"color: #d4d4d4;\">--) {</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #569cd6;\">const</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">element</span><span style=\"color: #d4d4d4;\"> = </span><span style=\"color: #569cd6;\">this</span><span style=\"color: #d4d4d4;\">.</span><span style=\"color: #9cdcfe;\">array</span><span style=\"color: #d4d4d4;\">[</span><span style=\"color: #9cdcfe;\">index</span><span style=\"color: #d4d4d4;\">];</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">reverseArray</span><span style=\"color: #d4d4d4;\">.</span><span style=\"color: #dcdcaa;\">push</span><span style=\"color: #d4d4d4;\">(</span><span style=\"color: #9cdcfe;\">element</span><span style=\"color: #d4d4d4;\">);</span></div><div><span style=\"color: #d4d4d4;\"> }</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #c586c0;\">return</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">reverseArray</span><span style=\"color: #d4d4d4;\">;</span></div><div><span style=\"color: #d4d4d4;\">}</span></div></div><p>On fait l\"inverse de la méthode forEach, à la place de commencer l\"index à 0 et de l\"incrémenter par 1, cette fois çi on commence par le nombre d\"éléments dans le tableau - 1, et on enlève 1 à chaque tour de boucle.<br>\n<br>\n\n- Et pour finir la méthode <strong>join</strong> :</p><div class=\"vscode-editor\" style=\"color: #d4d4d4;background-color: #1e1e1e;font-family: Consolas, \'Courier New\', monospace;font-weight: normal;font-size: 14px;line-height: 19px;white-space: pre;\"><div><span style=\"color: #6a9955;\">/**</span></div><div><span style=\"color: #6a9955;\"> * Crée et renvoie une nouvelle chaîne de caractères en concaténant tous les éléments d\'un tableau</span></div><div><span style=\"color: #6a9955;\"> * </span><span style=\"color: #569cd6;\">@param</span><span style=\"color: #6a9955;\"> </span><span style=\"color: #4ec9b0;\">{String}</span><span style=\"color: #6a9955;\"> </span><span style=\"color: #9cdcfe;\">separator</span><span style=\"color: #6a9955;\"> Ce paramètre optionnel indique une chaine de caractères pour séparer chaque élément du tableau</span></div><div><span style=\"color: #6a9955;\"> * </span><span style=\"color: #569cd6;\">@returns</span><span style=\"color: #6a9955;\"> </span><span style=\"color: #4ec9b0;\">{String}</span><span style=\"color: #6a9955;\"> Une chaîne de caractères composée de tous les éléments du tableau joints les uns aux autres.</span></div><div><span style=\"color: #6a9955;\"> */</span></div><div><span style=\"color: #dcdcaa;\">join</span><span style=\"color: #d4d4d4;\">(</span><span style=\"color: #9cdcfe;\">separator</span><span style=\"color: #d4d4d4;\"> = </span><span style=\"color: #ce9178;\">\",\"</span><span style=\"color: #d4d4d4;\">) {</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #569cd6;\">let</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">resultString</span><span style=\"color: #d4d4d4;\"> = </span><span style=\"color: #ce9178;\">\"\"</span><span style=\"color: #d4d4d4;\">;</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #569cd6;\">this</span><span style=\"color: #d4d4d4;\">.</span><span style=\"color: #dcdcaa;\">forEach</span><span style=\"color: #d4d4d4;\">((</span><span style=\"color: #9cdcfe;\">element</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #9cdcfe;\">index</span><span style=\"color: #d4d4d4;\">) </span><span style=\"color: #569cd6;\">=></span><span style=\"color: #d4d4d4;\"> {</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #c586c0;\">if</span><span style=\"color: #d4d4d4;\"> (</span><span style=\"color: #569cd6;\">this</span><span style=\"color: #d4d4d4;\">.</span><span style=\"color: #9cdcfe;\">array</span><span style=\"color: #d4d4d4;\">.</span><span style=\"color: #9cdcfe;\">length</span><span style=\"color: #d4d4d4;\"> - </span><span style=\"color: #b5cea8;\">1</span><span style=\"color: #d4d4d4;\"> === </span><span style=\"color: #9cdcfe;\">index</span><span style=\"color: #d4d4d4;\">) </span><span style=\"color: #c586c0;\">return</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">resultString</span><span style=\"color: #d4d4d4;\"> += </span><span style=\"color: #9cdcfe;\">element</span><span style=\"color: #d4d4d4;\">;</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">resultString</span><span style=\"color: #d4d4d4;\"> += </span><span style=\"color: #9cdcfe;\">element</span><span style=\"color: #d4d4d4;\"> + </span><span style=\"color: #9cdcfe;\">separator</span><span style=\"color: #d4d4d4;\">;</span></div><div><span style=\"color: #d4d4d4;\"> });</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #c586c0;\">return</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">resultString</span><span style=\"color: #d4d4d4;\">;</span></div><div><span style=\"color: #d4d4d4;\">}</span></div></div><p>Juste petite subtilité, on ne doit pas rajouter le séparateur à la dernière itrération de la boucle et donc pour ça on fait une simple condition.<br>\n<br>\nAlors ? Ce n\"est pas très compliqué, mais je trouve c\"est important de comprendre comment les méthodes/fonctions fonctionnent avant de s\"en servir et savoir les refaire c\"est toujours un bon plus même si en réalité dans un projet on ne va juste utiliser ces méthodes sans réfléchir comment elles fonctionnent.</p>', NULL, 1, '2020-04-29 20:16:09', '2020-05-06 10:50:26', 4),
|
|
(17, 'Est-ce un palindrome ?', 'isPalindrome', 'Un palindrome est un mot (ou phrase) qui peut s\'écrire dans les deux sens (ex: kayak).', '/images/functions/isPalindrome.png', 'form', '<p>Pour réfléchir sur un problème, il faut le \"découper\" en petits autres problèmes, un palindrome est un mot qui peut s\"écrire dans les deux sens, donc le mot avec les lettres inversées devrait être exactement le même que le mot initial.<br>\n\n\nDonc pour cela faut d\"abord faire une fonction qui va retourner la chaîne de caractère à l\"envers, par exemple : \"Hello\" devient \"olleH.</p><p>Je vais vous montrer 2 techniques différentes pour arriver à écrire la fonction \"reverseString\" :</p><p>- 1ère méthode consiste à simplement faire une boucle à l\"envers :</p><div class=\"vscode-editor\" style=\"color: #d4d4d4;background-color: #1e1e1e;font-family: Consolas, \'Courier New\', monospace;font-weight: normal;font-size: 14px;line-height: 19px;white-space: pre;\"><div><span style=\"color: #569cd6;\">function</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #dcdcaa;\">reverseString</span><span style=\"color: #d4d4d4;\">(</span><span style=\"color: #9cdcfe;\">string</span><span style=\"color: #d4d4d4;\">) {</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #569cd6;\">let</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">result</span><span style=\"color: #d4d4d4;\"> = </span><span style=\"color: #ce9178;\">\"\"</span><span style=\"color: #d4d4d4;\">;</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #569cd6;\">const</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #51b6c4;\">stringLength</span><span style=\"color: #d4d4d4;\"> = </span><span style=\"color: #9cdcfe;\">string</span><span style=\"color: #d4d4d4;\">.</span><span style=\"color: #9cdcfe;\">length</span><span style=\"color: #d4d4d4;\"> - </span><span style=\"color: #b5cea8;\">1</span><span style=\"color: #d4d4d4;\">;</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #c586c0;\">for</span><span style=\"color: #d4d4d4;\"> (</span><span style=\"color: #569cd6;\">let</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">index</span><span style=\"color: #d4d4d4;\"> = </span><span style=\"color: #9cdcfe;\">stringLength</span><span style=\"color: #d4d4d4;\">; </span><span style=\"color: #9cdcfe;\">index</span><span style=\"color: #d4d4d4;\"> >= </span><span style=\"color: #b5cea8;\">0</span><span style=\"color: #d4d4d4;\">; </span><span style=\"color: #9cdcfe;\">index</span><span style=\"color: #d4d4d4;\">--) {</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">result</span><span style=\"color: #d4d4d4;\"> += </span><span style=\"color: #9cdcfe;\">string</span><span style=\"color: #d4d4d4;\">[</span><span style=\"color: #9cdcfe;\">index</span><span style=\"color: #d4d4d4;\">];</span></div><div><span style=\"color: #d4d4d4;\"> }</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #c586c0;\">return</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">result</span><span style=\"color: #d4d4d4;\">;</span></div><div><span style=\"color: #d4d4d4;\">}</span></div></div><p>- 2ème méthode qui tient sur une seule ligne grâce aux méthodes des objets globaux :</p><div class=\"vscode-editor\" style=\"color: #d4d4d4;background-color: #1e1e1e;font-family: Consolas, \'Courier New\', monospace;font-weight: normal;font-size: 14px;line-height: 19px;white-space: pre;\"><div><span style=\"color: #569cd6;\">function</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #dcdcaa;\">reverseString</span><span style=\"color: #d4d4d4;\">(</span><span style=\"color: #9cdcfe;\">string</span><span style=\"color: #d4d4d4;\">) {</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #c586c0;\">return</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">string</span><span style=\"color: #d4d4d4;\">.</span><span style=\"color: #dcdcaa;\">split</span><span style=\"color: #d4d4d4;\">(</span><span style=\"color: #ce9178;\">\"\"</span><span style=\"color: #d4d4d4;\">).</span><span style=\"color: #dcdcaa;\">reverse</span><span style=\"color: #d4d4d4;\">().</span><span style=\"color: #dcdcaa;\">join</span><span style=\"color: #d4d4d4;\">(</span><span style=\"color: #ce9178;\">\"\"</span><span style=\"color: #d4d4d4;\">);</span></div><div><span style=\"color: #d4d4d4;\">}</span></div></div><p>Ici on \"split\" la chaîne de caractère sur chaque lettre (exemple: \"test\" devient [\"t\", \"e\", \"s\", \"t\"]), puis on utilise la méthode reverse() qui inverse le tableau et pour finir join qui nous permet d\"avoir une chaîne de caractères.</p><p>Maintenant, on peut rédiger la fonction \"isPalindrome\" : </p><div class=\"vscode-editor\" style=\"color: #d4d4d4;background-color: #1e1e1e;font-family: Consolas, \'Courier New\', monospace;font-weight: normal;font-size: 14px;line-height: 19px;white-space: pre;\"><div><span style=\"color: #569cd6;\">function</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #dcdcaa;\">isPalindrome</span><span style=\"color: #d4d4d4;\">(</span><span style=\"color: #9cdcfe;\">string</span><span style=\"color: #d4d4d4;\">) {</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #c586c0;\">return</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">string</span><span style=\"color: #d4d4d4;\"> === </span><span style=\"color: #dcdcaa;\">reverseString</span><span style=\"color: #d4d4d4;\">(</span><span style=\"color: #9cdcfe;\">string</span><span style=\"color: #d4d4d4;\">);</span></div><div><span style=\"color: #d4d4d4;\">}</span></div></div><p>Cette fonction nous renvoie simplement un booléen si oui ou non c\'est un palindrome.</p>', '[{\"name\": \"string\", \"type\": \"text\", \"label\": \"Entrez la chaîne de caractères à vérifier :\", \"placeholder\": \"(e.g : kayak)\"}]', 1, '2020-05-06 20:16:41', '2020-05-08 07:06:10', 2),
|
|
(18, 'Quel est le mot le plus long ?', 'findLongestWord', 'Trouve le mot le plus long dans une chaîne de caractères.', '/images/functions/findLongestWord.png', 'form', '<p></p><div class=\"vscode-editor\" style=\"color: #d4d4d4;background-color: #1e1e1e;font-family: Consolas, \'Courier New\', monospace;font-weight: normal;font-size: 14px;line-height: 19px;white-space: pre;\"><div><span style=\"color: #569cd6;\">function</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #dcdcaa;\">findLongestWord</span><span style=\"color: #d4d4d4;\">(</span><span style=\"color: #9cdcfe;\">string</span><span style=\"color: #d4d4d4;\">) {</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #569cd6;\">const</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #51b6c4;\">arrayString</span><span style=\"color: #d4d4d4;\"> = </span><span style=\"color: #9cdcfe;\">string</span><span style=\"color: #d4d4d4;\">.</span><span style=\"color: #dcdcaa;\">split</span><span style=\"color: #d4d4d4;\">(</span><span style=\"color: #ce9178;\">\" \"</span><span style=\"color: #d4d4d4;\">);</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #569cd6;\">let</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">wordLength</span><span style=\"color: #d4d4d4;\"> = </span><span style=\"color: #b5cea8;\">0</span><span style=\"color: #d4d4d4;\">;</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #569cd6;\">let</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">wordResult</span><span style=\"color: #d4d4d4;\"> = </span><span style=\"color: #ce9178;\">\"\"</span><span style=\"color: #d4d4d4;\">;</span></div><br><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">arrayString</span><span style=\"color: #d4d4d4;\">.</span><span style=\"color: #dcdcaa;\">forEach</span><span style=\"color: #d4d4d4;\">((</span><span style=\"color: #9cdcfe;\">word</span><span style=\"color: #d4d4d4;\">) </span><span style=\"color: #569cd6;\">=></span><span style=\"color: #d4d4d4;\"> {</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #c586c0;\">if</span><span style=\"color: #d4d4d4;\"> (</span><span style=\"color: #9cdcfe;\">word</span><span style=\"color: #d4d4d4;\">.</span><span style=\"color: #9cdcfe;\">length</span><span style=\"color: #d4d4d4;\"> > </span><span style=\"color: #9cdcfe;\">wordLength</span><span style=\"color: #d4d4d4;\">) {</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">wordResult</span><span style=\"color: #d4d4d4;\"> = </span><span style=\"color: #9cdcfe;\">word</span><span style=\"color: #d4d4d4;\">;</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">wordLength</span><span style=\"color: #d4d4d4;\"> = </span><span style=\"color: #9cdcfe;\">word</span><span style=\"color: #d4d4d4;\">.</span><span style=\"color: #9cdcfe;\">length</span><span style=\"color: #d4d4d4;\">;</span></div><div><span style=\"color: #d4d4d4;\"> }</span></div><div><span style=\"color: #d4d4d4;\"> });</span></div><br><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #c586c0;\">return</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">wordResult</span><span style=\"color: #d4d4d4;\">;</span></div><div><span style=\"color: #d4d4d4;\">}</span></div></div><p>On part du principe que chaque mot est séparé par des espaces. Au début, le mot le plus long a 0 caractère. Puis on fait une boucle qui vérifie si le mot qu\'on est en train de vérifier est plus long que le mot qui était jusqu\'à cette itération le plus long, si c\'est le cas, on met à jour les variables du mot le plus long, pour vérifier si c\'est encore le cas à la prochaine itération.</p>', '[{\"name\": \"string\", \"type\": \"text\", \"label\": \"Entrez la chaîne de caractères (phrase) à vérifier :\", \"placeholder\": \"(e.g : Une phrase quelconque.)\"}]', 1, '2020-05-06 20:29:05', '2020-05-08 07:23:23', 2),
|
|
(19, 'Suite de Fibonacci', 'fibonacci', 'Calcule la suite de Fibonacci.', '/images/functions/fibonacci.png', 'form', '<p>La suite de Fibonacci est une suite d\"entiers dans laquelle chaque terme est la somme des deux termes qui le précèdent, voici les 6 premiers chiffres de la suite :<br>\n\n\n\n\n\n0, 1, 1, 2, 3, 5</p><p>Nous allons coder une fonction récursive qui va nous calculer les \"x\" premiers nombres de la suite.</p><p>Pour commencer qu\"est ce qu\"une fonction récursive ? Une fonction récursive est une fonction qui s\"auto appelle dans le corps de la fonction, exemple :</p><div class=\"vscode-editor\" style=\"color: #d4d4d4;background-color: #1e1e1e;font-family: Consolas, \'Courier New\', monospace;font-weight: normal;font-size: 14px;line-height: 19px;white-space: pre;\"><div><span style=\"color: #569cd6;\">function</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #dcdcaa;\">doSomeCode</span><span style=\"color: #d4d4d4;\">() {</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #dcdcaa;\">doSomeCode</span><span style=\"color: #d4d4d4;\">();</span></div><div><span style=\"color: #d4d4d4;\">}</span></div><div><span style=\"color: #dcdcaa;\">doSomeCode</span><span style=\"color: #d4d4d4;\">();</span></div></div><p>Bon ici, ça n\"a pas trop de sens, car ça causerait \"une boucle infinie\" on obtiendra une \"InternalError: too much recursion\", par contre si on exécute la fonction ou on retourne une valeur d\"après des conditions, ça peut-être très intéressant.</p><div class=\"vscode-editor\" style=\"color: #d4d4d4;background-color: #1e1e1e;font-family: Consolas, \'Courier New\', monospace;font-weight: normal;font-size: 14px;line-height: 19px;white-space: pre;\"><div><span style=\"color: #569cd6;\">function</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #dcdcaa;\">fibonacci</span><span style=\"color: #d4d4d4;\">(</span><span style=\"color: #9cdcfe;\">counter</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #9cdcfe;\">result</span><span style=\"color: #d4d4d4;\"> = [], </span><span style=\"color: #9cdcfe;\">number1</span><span style=\"color: #d4d4d4;\"> = </span><span style=\"color: #b5cea8;\">0</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #9cdcfe;\">number2</span><span style=\"color: #d4d4d4;\"> = </span><span style=\"color: #b5cea8;\">1</span><span style=\"color: #d4d4d4;\">) {</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #c586c0;\">if</span><span style=\"color: #d4d4d4;\"> (</span><span style=\"color: #9cdcfe;\">counter</span><span style=\"color: #d4d4d4;\"> === </span><span style=\"color: #b5cea8;\">0</span><span style=\"color: #d4d4d4;\">) {</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #c586c0;\">return</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">result</span><span style=\"color: #d4d4d4;\">; </span></div><div><span style=\"color: #d4d4d4;\"> }</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">counter</span><span style=\"color: #d4d4d4;\">--;</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">result</span><span style=\"color: #d4d4d4;\">.</span><span style=\"color: #dcdcaa;\">push</span><span style=\"color: #d4d4d4;\">(</span><span style=\"color: #9cdcfe;\">number1</span><span style=\"color: #d4d4d4;\">);</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #c586c0;\">return</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #dcdcaa;\">fibonacci</span><span style=\"color: #d4d4d4;\">(</span><span style=\"color: #9cdcfe;\">counter</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #9cdcfe;\">result</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #9cdcfe;\">number2</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #9cdcfe;\">number1</span><span style=\"color: #d4d4d4;\"> + </span><span style=\"color: #9cdcfe;\">number2</span><span style=\"color: #d4d4d4;\">);</span></div><div><span style=\"color: #d4d4d4;\">}</span></div></div><p>Cette fonction a en réalité un seul argument qui doit être passé lors de la première exécution, le \"counter\", le reste c\'est des arguments qu\"on passera dans le corps de la fonction quand on la réecutera.</p><p>On décrémente counter de -1 à chaque itération donc si counter est égale à 0 c\"est qu\"il faut retourner la suite de nombres sinon on peut continuer à push des nombres dans la liste.<br>\nPour rajouter des nombres dans la liste, il nous faut 2 variables (les deux termes qui précèdent) qui ici nous appelons \"number1\" et \"number2\".</p>', '[{\"name\": \"counter\", \"type\": \"integer\", \"label\": \"Combien de nombres de la suite de fibonacci voulez vous calculer ?\", \"placeholder\": \"(e.g : 14)\"}]', 1, '2020-05-06 20:43:21', '2020-05-08 12:02:53', 2);
|
|
INSERT INTO `functions` (`id`, `title`, `slug`, `description`, `image`, `type`, `article`, `utilizationForm`, `isOnline`, `createdAt`, `updatedAt`, `categorieId`) VALUES
|
|
(20, 'Trie les éléments d\'un tableau', 'sortArray', 'Trie les éléments d\'un tableau dans l\'ordre croissant.', '/images/functions/sortArray.png', 'form', '<p>Le but ici c\"est de recevoir un tableau de nombres et de pouvoir remettre dans l\"ordre croissant le tableau (exemple : [4, 12, 1, 8] devient [1, 4, 8, 12]).</p><p>Comme je le dis souvent, il faut penser un problème en petits autres problèmes plus facilement atteignable. Pour commencer, je décide de faire une fonction qui me retourne le nombre le plus petit d\"un tableau.<br>\n</p><div class=\"vscode-editor\" style=\"color: #d4d4d4;background-color: #1e1e1e;font-family: Consolas, \'Courier New\', monospace;font-weight: normal;font-size: 14px;line-height: 19px;white-space: pre;\"><div><span style=\"color: #569cd6;\">function</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #dcdcaa;\">minNumber</span><span style=\"color: #d4d4d4;\">(</span><span style=\"color: #9cdcfe;\">array</span><span style=\"color: #d4d4d4;\">) {</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #569cd6;\">let</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">minNumber</span><span style=\"color: #d4d4d4;\"> = { </span><span style=\"color: #9cdcfe;\">index:</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #b5cea8;\">0</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #9cdcfe;\">value:</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">array</span><span style=\"color: #d4d4d4;\">[</span><span style=\"color: #b5cea8;\">0</span><span style=\"color: #d4d4d4;\">] };</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #c586c0;\">for</span><span style=\"color: #d4d4d4;\"> (</span><span style=\"color: #569cd6;\">let</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">index</span><span style=\"color: #d4d4d4;\"> = </span><span style=\"color: #b5cea8;\">1</span><span style=\"color: #d4d4d4;\">; </span><span style=\"color: #9cdcfe;\">index</span><span style=\"color: #d4d4d4;\"> < </span><span style=\"color: #9cdcfe;\">array</span><span style=\"color: #d4d4d4;\">.</span><span style=\"color: #9cdcfe;\">length</span><span style=\"color: #d4d4d4;\">; </span><span style=\"color: #9cdcfe;\">index</span><span style=\"color: #d4d4d4;\">++) {</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #569cd6;\">const</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #51b6c4;\">number</span><span style=\"color: #d4d4d4;\"> = </span><span style=\"color: #9cdcfe;\">array</span><span style=\"color: #d4d4d4;\">[</span><span style=\"color: #9cdcfe;\">index</span><span style=\"color: #d4d4d4;\">];</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #c586c0;\">if</span><span style=\"color: #d4d4d4;\"> (</span><span style=\"color: #9cdcfe;\">number</span><span style=\"color: #d4d4d4;\"> < </span><span style=\"color: #9cdcfe;\">minNumber</span><span style=\"color: #d4d4d4;\">.</span><span style=\"color: #9cdcfe;\">value</span><span style=\"color: #d4d4d4;\">) {</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">minNumber</span><span style=\"color: #d4d4d4;\"> = { </span><span style=\"color: #9cdcfe;\">index:</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">index</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #9cdcfe;\">value:</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">array</span><span style=\"color: #d4d4d4;\">[</span><span style=\"color: #9cdcfe;\">index</span><span style=\"color: #d4d4d4;\">] };</span></div><div><span style=\"color: #d4d4d4;\"> }</span></div><div><span style=\"color: #d4d4d4;\"> }</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #c586c0;\">return</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">minNumber</span><span style=\"color: #d4d4d4;\">;</span></div><div><span style=\"color: #d4d4d4;\">}</span></div></div><p>Cette fonction retourne un objet contenant la valeur ainsi que son index du nombre le plus petit du tableau passé en argument.</p><p>Ensuite on peut passer à la fonction sortArray :</p><div class=\"vscode-editor\" style=\"color: #d4d4d4;background-color: #1e1e1e;font-family: Consolas, \'Courier New\', monospace;font-weight: normal;font-size: 14px;line-height: 19px;white-space: pre;\"><div><span style=\"color: #569cd6;\">function</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #dcdcaa;\">sortArray</span><span style=\"color: #d4d4d4;\">(</span><span style=\"color: #9cdcfe;\">array</span><span style=\"color: #d4d4d4;\">) {</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #569cd6;\">const</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #51b6c4;\">arrayDuplicated</span><span style=\"color: #d4d4d4;\"> = [...</span><span style=\"color: #9cdcfe;\">array</span><span style=\"color: #d4d4d4;\">];</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #569cd6;\">const</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #51b6c4;\">resultArray</span><span style=\"color: #d4d4d4;\"> = [];</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #c586c0;\">while</span><span style=\"color: #d4d4d4;\"> (</span><span style=\"color: #9cdcfe;\">array</span><span style=\"color: #d4d4d4;\">.</span><span style=\"color: #9cdcfe;\">length</span><span style=\"color: #d4d4d4;\"> !== </span><span style=\"color: #9cdcfe;\">resultArray</span><span style=\"color: #d4d4d4;\">.</span><span style=\"color: #9cdcfe;\">length</span><span style=\"color: #d4d4d4;\">) {</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #569cd6;\">const</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #51b6c4;\">min</span><span style=\"color: #d4d4d4;\"> = </span><span style=\"color: #dcdcaa;\">minNumber</span><span style=\"color: #d4d4d4;\">(</span><span style=\"color: #9cdcfe;\">arrayDuplicated</span><span style=\"color: #d4d4d4;\">);</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">resultArray</span><span style=\"color: #d4d4d4;\">.</span><span style=\"color: #dcdcaa;\">push</span><span style=\"color: #d4d4d4;\">(</span><span style=\"color: #9cdcfe;\">min</span><span style=\"color: #d4d4d4;\">.</span><span style=\"color: #9cdcfe;\">value</span><span style=\"color: #d4d4d4;\">);</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">arrayDuplicated</span><span style=\"color: #d4d4d4;\">.</span><span style=\"color: #dcdcaa;\">splice</span><span style=\"color: #d4d4d4;\">(</span><span style=\"color: #9cdcfe;\">min</span><span style=\"color: #d4d4d4;\">.</span><span style=\"color: #9cdcfe;\">index</span><span style=\"color: #d4d4d4;\">, </span><span style=\"color: #b5cea8;\">1</span><span style=\"color: #d4d4d4;\">);</span></div><div><span style=\"color: #d4d4d4;\"> }</span></div><div><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #c586c0;\">return</span><span style=\"color: #d4d4d4;\"> </span><span style=\"color: #9cdcfe;\">resultArray</span><span style=\"color: #d4d4d4;\">;</span></div><div><span style=\"color: #d4d4d4;\">}</span></div></div><p>Je duplique mon tableau (\"arrayDuplicated\") grâce au spread operator, c\'est sur ce tableau que je vais supprimer le nombre minimum pour l\'ajouter au tableau de resultat (\"resultArray\"), je fais une boucle while tant que le tableau de résultats n\'est pas égale au tableau initiale c\'est qu\'il faut rajouter encore des valeurs et continuer la boucle, splice modifie le tableau et \"array.splice(index, 1)\" permet de supprimer l\'élément à l\'index voulu, ici l\'index du nombre qu\'on a ajouté au tableau de résultat.</p>', '[{\"name\": \"numbersList\", \"type\": \"text\", \"label\": \"Entrez une liste de nombres (séparées par des virgules) :\", \"placeholder\": \"(e.g : 4, 12, 1, 8)\"}]', 1, '2020-05-06 20:57:48', '2020-05-08 13:17:26', 2); |