Double 'each' loop to find the smallest value in an Array
I'm trying to implement the Pinterest wall, as described here : http://stackoverflow.com/questions/7109362/how-to-replicate-pinterest-coms-absolute-div-stacking-layout/7128902#7128902

Anyway, I'm stuck at one point where I need to find the *index* of the **smallest value** in an Array, but at the same time, **add the height** of my *current* block to that value (so that the smallest value isn't always the same).

    var grid = new Array(4); // 4 as example
    
    // Add values to the Array
    $.each(grid, function(j) {
    	grid[j] = j;
    });
    var smallest_index = 0;
    var smallest_value = grid[0];
    
    // Find the index of the smallest value in the Array
    SmallestValueIndex = function() {
    	$.each(grid, function(i, v) {
    		if (v < smallest_value) {
    			smallest_index = i;
    			smallest_value = v;
    		}
    	});
    }
    
    // Go through all my '<div>' and add the height to the current smallest value
    $.each(blocs, function() {
    	SmallestValueIndex();
    	var h = $(this).height();
    	grid[smallest_index] += h;
    });


Each time, the smallest value should be different because I add the height to the *previous* smallest value (so it's not the smallest value anymore).

But in my tests, it remains the same.

Double 'each' loop to find the smallest value in an Array
===

I'm trying to implement the Pinterest wall, as described here : http://stackoverflow.com/questions/7109362/how-to-replicate-pinterest-coms-absolute-div-stacking-layout/7128902#7128902

Anyway, I'm stuck at one point where I need to find the *index* of the **smallest value** in an Array, but at the same time, **add the height** of my *current* block to that value (so that the smallest value isn't always the same).

    var grid = new Array(4); // 4 as example
    
    // Add values to the Array
    $.each(grid, function(j) {
    	grid[j] = j;
    });
    var smallest_index = 0;
    var smallest_value = grid[0];
    
    // Find the index of the smallest value in the Array
    SmallestValueIndex = function() {
    	$.each(grid, function(i, v) {
    		if (v < smallest_value) {
    			smallest_index = i;
    			smallest_value = v;
    		}
    	});
    }
    
    // Go through all my '<div>' and add the height to the current smallest value
    $.each(blocs, function() {
    	SmallestValueIndex();
    	var h = $(this).height();
    	grid[smallest_index] += h;
    });


Each time, the smallest value should be different because I add the height to the *previous* smallest value (so it's not the smallest value anymore).

But in my tests, it remains the same.
