Let's try for one pass through the numbers.

function test() {
  for (var j=0;j<5;j++) {
    for (var k=0;k<g_numbers[j];k++) fd();
    rt();
  }
}

All being well you should end up with the first of the pictures below.

Study all the pictures and you should see that we need to repeat the above 4 times to get the complete spirolateral.

function test() {
  for (var i=0;i<4;i++) {
    for (var j=0;j<5;j++) {
      for (var k=0;k<g_numbers[j];k++) fd();
      rt();
    }
  }
}