Guest User

Untitled

a guest
Feb 21st, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var chaine = prompt("Veuillez entrer une chaîne de caractères :"), i, preminst = 1, block = '', block2 = '';
  2.  
  3. function plusGrandBlock(texte)
  4. {
  5. for (i = 1; i <= texte.length; i++)
  6. {
  7.   if(texte[i] == texte[i-1])
  8.   {
  9.     if(preminst == 0)
  10.     {
  11.       block = block + texte[i];
  12.     }
  13.     else
  14.     {
  15.       block = block + texte[i] + texte[i-1];
  16.       preminst = 0;
  17.     }
  18.   }
  19.   else
  20.   {
  21.     if(block.length > block2.length)
  22.     {
  23.       block2 = block;
  24.     }
  25.     block = '';
  26.     preminst = 1;
  27.   }
  28. }
  29.  
  30.   return block2;
  31. }
  32.  
  33. print("Le « block » le plus long dans la chaîne « " + chaine + " » est : « " + plusGrandBlock(chaine) + " ».");
Add Comment
Please, Sign In to add comment