function recurseCombos(partial, photosReserved, combos) {
        if (combos.length >= 30) {
          // Consider a maximum of 30 combinations for any iteration of this.
          return;
        }
        
        if (partial.length === 3 || photosReserved === photos.length) {
          // If the partial combo contains three rows OR we are out of photos, this combination is complete.
          combos.push(partial);
          return;
        }
        
        // For the current partial combination, compute possibilities for the next row.  We will consider
        // each row of ideal height, plus up to one overheight and one underheight row.
        var row = [];
        var aspect = 0;
        var overheightRow = null;
        var i;
    
        for (i = photosReserved; i < photos.length; i += 1) {
           // Add photo to next row.
          row = row.slice(0);
          row.push(photos[i]);
          
          // Calculate ideal height of this row, preserving aspect.
          aspect += photos[i].get('aspect_ratio');
          
          if (aspect < minPhotoRowAspect) {
            overheightRow = [row, i];
          } else {
            // Add this row to the current partial combination and calculate
            // the next set of possible rows.
            recurseCombos(partial.concat([row]), i + 1, combos);
            if (aspect < maxPhotoRowAspect) {
              break;
            }
          }
        } 
        
        if (overheightRow) {
          recurseCombos(partial.concat([overheightRow[0]]), overheightRow[1] + 1, combos);
        }
      }
// Recursive function to find all viable candidate combinations for laying out the next three rows.
Recursive function to find all viable candidate combinations for laying out the next three rows.
Recursive function to find all viable candidate combinations for laying out the next three rows .
function recurseCombos(partial, photosReserved, combos) {
        if (combos.length >= 30) {
          return;
        }
        if (partial.length === 3 || photosReserved === photos.length) {
          combos.push(partial);
          return;
        }
        var row = [];
        var aspect = 0;
        var overheightRow = null;
        var i;
        for (i = photosReserved; i < photos.length; i += 1) {
          row = row.slice(0);
          row.push(photos[i]);
          aspect += photos[i].get('aspect_ratio');
          if (aspect < minPhotoRowAspect) {
            overheightRow = [row, i];
          } else {
            recurseCombos(partial.concat([row]), i + 1, combos);
            if (aspect < maxPhotoRowAspect) {
              break;
            }
          }
        } 
        if (overheightRow) {
          recurseCombos(partial.concat([overheightRow[0]]), overheightRow[1] + 1, combos);
        }
      }
function recurseCombos ( partial , photosReserved , combos ) { if ( combos . length >= 30 ) { return ; } if ( partial . length === 3 || photosReserved === photos . length ) { combos . push ( partial ) ; return ; } var row = [ ] ; var aspect = 0 ; var overheightRow = null ; var i ; for ( i = photosReserved ; i < photos . length ; i += 1 ) { row = row . slice ( 0 ) ; row . push ( photos [ i ] ) ; aspect += photos [ i ] . get ( 'aspect_ratio' ) ; if ( aspect < minPhotoRowAspect ) { overheightRow = [ row , i ] ; } else { recurseCombos ( partial . concat ( [ row ] ) , i + 1 , combos ) ; if ( aspect < maxPhotoRowAspect ) { break ; } } } if ( overheightRow ) { recurseCombos ( partial . concat ( [ overheightRow [ 0 ] ] ) , overheightRow [ 1 ] + 1 , combos ) ; } }
Recursive function to find all viable candidate combinations for laying out the next three rows.
Recursive function to find all viable candidate combinations for laying out the next three rows .
// Consider a maximum of 30 combinations for any iteration of this. // If the partial combo contains three rows OR we are out of photos, this combination is complete. // For the current partial combination, compute possibilities for the next row.  We will consider // each row of ideal height, plus up to one overheight and one underheight row. // Add photo to next row. // Calculate ideal height of this row, preserving aspect. // Add this row to the current partial combination and calculate // the next set of possible rows.