title: How can I scale an array of values while maintaining a minimum value?
body: <p>So I have an array of values that I need to scale down while maintaining a minimum value for the scaled value. </p>
  
  <p>For example, let's say I have an array of values <code>[1, 1, 3, 5]</code> with a minimum scale factor of <code>.2</code>. </p>
  
  <p>By normalizing the array, we get the array <code>[.1, .1, .3, .5]</code>. However, keeping in mind the minimum scale factor, we'd have values <code>[.2, .2, .3, .5]</code>, which adds up to <code>1.2</code>, not <code>1</code>. </p>
  
  <p>My thinking was to iterate over the array and first set all values that would be under the minimum to the minimum, keeping a carry variable to determine how much still needs to be redistributed to the other elements in the array that were over the minimum. </p>
  
  <p>With all of the values that were over the minimum, scale their values with respect to the carry variable and then subtract that from their values. </p>
  
  <p>So with the example above, we'd subtract <code>3/8 * .2</code> from <code>.3</code>, and <code>5/8 * .2</code> from <code>.5</code> to get <code>[.2, .2, .225, .375]</code>. </p>
  
  <p>Is there any other way to do this more efficiently? Or an alternative way to scale the remaining values? </p>
  
  <hr>
  
  <p>Edit: Sorry, scaling might be the incorrect term, but in the end the values of the array are to be divided in such a way that their values are changed with respect to the total value. </p>
  
  <p>I'll explain the specific implementation so that the question might be more clear:</p>
  
  <p>I have a number of posts, and each of the posts is to be shown for a certain amount of time before fading out, after which the next post is to be shown. I want the delay between posts to be dependent on the number of <em>words</em> within each post, but also constrained to be at least some minimum value. </p>
  
  <p>There is a <em>total amount of time</em> for all of the posts to be shown, and the time is supposed to be split up between all of the posts. </p>