How to create a 2d array whose dimensions are specified by the user (in jQuery)

I need to create a 2D array with the size specified in the input fields. And fill in the generated fields so that they rotate clockwise, starting from the lower right corner.

enter image description here

I managed to create a 2D array, but I do not know how to fill it. Any help is appreciated.

$("button").click(function() { var brr=parseInt($("#brr").val()); var brs=parseInt($("#brs").val()); for (i=1; i<=brs; i++) { for (j=1; j<=brr; j++) { $("#output").append("<div class='k'>o</div>"); } $("#output").append("<br/>"); } }) 
+5
source share
2 answers

something like that?

http://jsfiddle.net/mig1098/d0beygLp

 $("#button").click(function() { $("#output").html(''); var brs1=parseInt($("#brs1").val()); var brs2=parseInt($("#brs2").val()); var c=0; for (i=1; i<=brs1; i++){ for (j=1; j<=brs2; j++){ $("#output").append("<div class='k'>"+c+"</div>"); c++; } $("#output").append("<div class=\"clearfix\"></div>"); } }); 
+1
source

You can fill it out as follows: DIRECT EXAMPLE HERE

  $("button").click(function() { var brr=parseInt($("#brr").val()); var brs=parseInt($("#brs").val()); var counter = brr * brs; for (i=1; i<=brs; i++){ for (j=1; j<=brr; j++) { $("#output").append("<div class='k'>" + (counter--) + "</div>"); } $("#output").append("<br/>"); } }); 
0
source

Source: https://habr.com/ru/post/1209142/


All Articles