I need to create a 2D array with dimension specified in input fields. And fill the generated fields so that it spirals clock-wise, starting from the bottom right corner.

I managed to create the 2D array but I don't 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/>");
    }
})
                something like this?
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>");
    }
});
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With