Simplified Bin Packing using JavaScript
I think a big first improvement for you will be to start DRYing out your code. You should create a function which returns the ratio of two sides -- there is much too much repetition in your code. Something like:

function get_ratio(x, y) {
    if (y === 0) {
        return 0
    }
    return x/y | 0
}