Q:

JavaScript - Array of pairs

I need to write a method that, when given a number, constructs an array the length of that number. For instance:
var myArray = constructArray(6);

Now, this is the important part. The array it constructs needs to pair numbers. For instance, if I gave the number 6, the result it returns would look like this:
[2, 2, 1, 1, 0, 0]

And If I gave 5:
[2, 1, 1, 0, 0]

If I gave 4:
[1, 1, 0, 0]

Yeah, you get the point! The numbers are backwards and in pairs (when the length provided is even).
I'm creating a book in CSS and the stacking order (z-index) of the elements needs to follow this pattern, so that pages on top in the DOM are actually on top aesthetically.

A:

function constructArray(length){
    var result = [];
    for (var i = 0; i < length; i++){
        result.unshift(Math.floor(i / 2));
    }    
    return result;
}

