This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <title>demo html</title> | |
| </head> | |
| <body> | |
| <h3>jeux morpion</h3> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Version lisible pour débutants | |
| function add(...nombres) { | |
| let somme = 0; | |
| for (nombre of nombres) { | |
| somme = somme + nombre; | |
| } | |
| return somme; | |
| } | |
| // Version avancée plus compacte |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Version lisible pour débutants | |
| function allLongestStrings(tableauDeChaines) { | |
| let longueurMax = 0; | |
| for (chaine of tableauDeChaines) { | |
| if (longueurMax < chaine.length) { | |
| longueurMax = chaine.length; | |
| } | |
| } | |
| let plusLonguesChaines = []; | |
| for (chaine of tableauDeChaines) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Version lisible pour débutants | |
| function alternatingSums(tableau) { | |
| let sommePaires = 0; | |
| let sommeImpaires = 0; | |
| for (let i = 0; i < tableau.length; i++) { | |
| if (i % 2 === 0) { | |
| sommePaires = sommePaires + tableau[i]; | |
| } else { | |
| sommeImpaires = sommeImpaires + tableau[i]; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Version lisible pour débutants | |
| function arrayReplace(tableau, nombreARemplacer, nouvelleValeur) { | |
| const resultat = []; | |
| for(nombre of tableau) { | |
| if (nombre === nombreARemplacer) { | |
| resultat.push(nouvelleValeur); | |
| } else { | |
| resultat.push(nombre); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Version lisible pour débutants | |
| function caseInsensitivePalindrome(mot) { | |
| // On met tout en minuscules pour rester insensible à la casse | |
| mot = mot.toLowerCase(); | |
| // On transforme la chaîne en tableau de caractères... | |
| let palindrome = mot.split(''); | |
| // ...pour pouvoir utiliser les méthodes des tableaux | |
| // et ainsi "retourner" facilement le mot | |
| palindrome = palindrome.reverse().join(''); | |
| // On teste si le mot retourné est égal au mot |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Solution simple via concaténation | |
| function encloseInBrackets(chaine) { | |
| return '(' + chaine + ')'; | |
| } | |
| // Solution simple via template strings | |
| function encloseInBrackets(chaine) { | |
| return `(${chaine})`; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Solution classique grâce à la récursivité | |
| function factorialNumber(num) { | |
| if (num !== 1) { | |
| return num * factorialNumber(num - 1); | |
| } else return 1; | |
| } | |
| // Solution sans récursivité | |
| function factorialNumber(num) { | |
| let resultat = 1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Version lisible pour les débutants | |
| // Gère les espaces dans chaine | |
| function firstDigit(chaine) { | |
| for (caractere of chaine) { | |
| if ("0123456789".includes(caractere)) { | |
| return caractere; | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Version lisible pour les débutants | |
| function largestNumber(num) { | |
| // On concatène plusieurs 9 côte à côte | |
| const nombreChaine = '9'.repeat(num); | |
| // On convertit la chaîne en un nombre | |
| return Number(nombreChaine); | |
| } | |
| // Version compacte de la solution précédente | |
| function largestNumber(num) { |
OlderNewer