Hello all!

Can someone help with this matrix? it needs to spiral inwards, from bottom right corner, clockwise...

I found this code... and it runs nicely but I need to adapt it in some ways:
- I should be able to provide number of rows and columns
- the grid should start from number 1
- it should start from bottom right corner, clockwise...

I will put the code that works, but not the way I need... can someone at least decipher it for me so I could try to do it??


<!doctype html>
<meta charset="utf-8">
<title>Untitled Document</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<script type="text/javascript">

spiralArray = function (edge) {
    var arr = Array(edge),
        x = 0, y = edge,
        total = edge * edge--,
        dx = 1, dy = 0,
        i = 0, j = 0;
    while (y) arr[--y] = [];
    while (i < total) {
        arr[y][x] = i++;
        x += dx; y += dy;
        if (++j == edge) {
            if (dy < 0) {x++; y++; edge -= 2}
            j = dx; dx = -dy; dy = j; j = 0;
    return arr;

// T E S T:
arr = spiralArray(edge = 3);
for (y= 0; y < edge; y++) console.log(arr[y].join(" "));




I'm totally confused what on earth you want this to do. When I ran it, it gave me an alert that said:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.