two dimensional array horizontal average output

后端 未结 7 488
故里飘歌
故里飘歌 2021-01-24 05:20

I am stuck with a problem and i don\'t know how to put this in a for loop. I need the hotizontal average of the next matrix:

1 2 3 4 5

5 4 3 2 1

3 2 1 4 5
         


        
7条回答
  •  失恋的感觉
    2021-01-24 05:53

    You can do like follows in javascript :

    Have a div like

    and add the javascript code :

    var dArray = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [3, 2, 1, 4, 5]];
     var texts='';
        for (i=0; i" ;
           dArray[i][dArray[i].length]=avg;
    
        }
     document.getElementById("matrix_output").innerHTML=texts;
    

    Check the below link for reference :

    http://jsfiddle.net/xGZPL/

提交回复
热议问题