Array con frequenze - Alessandro Barazzuol

Array con frequenze

<!DOCTYPE html>
<!--
Alessandro Barazzuol
-->
<html>
    <head>
        <title></title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        
        
        <script>
            let freq=[0];
            let array=[0];
            const SIZE=20;
            
            function spara()
            {
                for (let i = document.getElementById("bodi").childNodes.length - 1; i >= 0; i--) {
                document.getElementById("bodi").removeChild(document.getElementById("bodi").childNodes[i]);
                }
                
                for(i=0;i<=90;i++)
                freq[i]=0;
            
                frequenze();
                
                document.getElementById("t").innerHTML=array.toString().trim();
              
                var table=document.createElement("table");
                document.getElementById("bodi").appendChild(table);
                var tr;
                
                for(i=65;i<=90;i++)
                {
                    if(freq[i]!=0)
                    {
                        tr=document.createElement("tr");
                        
                    
                        var td=document.createElement("td");
                        td.style.width = '10%';
                        td.innerHTML=String.fromCharCode(i);
                        tr.appendChild(td);
                     
                        for(j=0;j<freq[i];j++)
                        {
                            td=document.createElement("td");
                            td.style.backgroundColor="Red";
                            td.style.backgroundImage=" linear-gradient(red, yellow)";
                            tr.appendChild(td);
                        }
                         
                         table.appendChild(tr);  
                    }
                   
                 
                }
                
            }
            
            function frequenze()
            {
    
                for(i =0;i<SIZE;i++)
                {
                    array[i]=String.fromCharCode(Math.floor(Math.random()*26+65));
                   
                }
                for(i =0;i<SIZE;i++)
                {
                   
                    freq[array[i].charCodeAt(0)]++;
                   
                }
                
            }
        </script><!-- comment -->
    </head>
     
    
    
     <p id="t"  ></p><br><!-- comment -->
     <input type="button" value="Random" onclick="spara()">  <br><!-- comment -->
     <div>Grafico Frequenze lettere</div><br>
        
     <div id="bodi">
        
       
       <!-- codice tabella -->
       
     </div>
     
</html>
Frequenze



Grafico Frequenze lettere