title: How to filter elements based on height to fit into a container
body: <p>Maybe this is more of a maths question, I just don't know how to start calculating.</p>
  
  <p><img src="https://i.stack.imgur.com/povQg.png" alt="Waveform"></p>
  
  <p>I have an array of elements(Wave peaks). </p>
  
  <p>These elements come with different heights for different arrays, but the width for each element is 2px with a right margin of 1px.</p>
  
  <p>These elements have to be appended into a container div to form an interactive audio wave. Width of the container is 700px, so only about 233.5 elements can fit into the container at max.</p>
  
  <p>How do I filter the elements to fit into the container by not appending elements with smaller heights so that the elements in the container come close to being >= 232 &lt; 234.</p>
  
  <p>Here's a Fiddle of this example. <a href="https://jsfiddle.net/8ko3dozj/" rel="nofollow noreferrer">https://jsfiddle.net/8ko3dozj/</a></p>
  
  <pre><code>$.create_waves = function(){    
              $.append = function(h){
              $.each(wave_columns, function(index, item){
                  var peak_height = item*max_peak_remaining_space;
                  if (item &gt; h){
                  var wave_peak_div = '&lt;nav class="wave_column_div"&gt;\
                  &lt;div class="wave_column_div_inner" data-height="'+peak_height+'"&gt;\
                  &lt;/div&gt;\
                  &lt;/nav&gt;';
                  $('#wave_result').append(wave_peak_div);
                  }
              });
              }
              var length = wave_columns.length;
              //alert(length);
          $.append(0.3);  
          $.animate_peak_height();
          var num_peaks = $('.wave_column_div').length;
          if (num_peaks &lt; 233){
              //$.append(0.5);
              }
          }       
          $.create_waves();
  </code></pre>
  
  <p><strong>Notes:</strong> I don't want to use overflow:hidden for more than 3 elements(peaks) as that will take out the important parts of the audio used for seeking. Taking out low peaks zooms the waveform, as I see it, that's why I prefer it that way.  </p>