Advertisement
ikov34

Untitled

Sep 8th, 2021
1,439
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. function nakljucnoStevilo(min, max) {
  3.   return Math.floor(Math.random() * (max - min)) + min;
  4. }
  5.  
  6. function posodobiTabeloStatistike(statistika) {
  7.   // Algoritem urejanja števil Bubble sort v nenaraščajoče zaporedje
  8.   for (let i = statistika.length - 1; i > 0; --i) {
  9.     for (let j = 0; j < i; ++j) {
  10.       if (statistika[j + 1].tocke > statistika[j].tocke) {
  11.         // Če je naslednik večji od predhodnika, moramo zamenjati
  12.         // Menjava dveh vrednosti
  13.         let menjava = statistika[j];
  14.         statistika[j] = statistika[j + 1];
  15.         statistika[j + 1] = menjava;
  16.       }
  17.     }
  18.   }
  19.   // Posodobimo tabelo
  20.   let stari_tbody = document.querySelector("tbody");
  21.   let novi_tbody = document.createElement("tbody");
  22.   for (let i = 0; i < statistika.length; ++i) {
  23.     let vrstica = document.createElement("tr");
  24.     let stolpecIme = document.createElement("td");
  25.     let stolpecTocke = document.createElement("td");
  26.  
  27.     stolpecIme.innerText = statistika[i].ime;
  28.     stolpecTocke.innerText = statistika[i].tocke;
  29.  
  30.     vrstica.appendChild(stolpecIme);
  31.     vrstica.appendChild(stolpecTocke);
  32.     novi_tbody.appendChild(vrstica);
  33.   }
  34.   stari_tbody.parentNode.replaceChild(novi_tbody, stari_tbody);
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement