title: Mapping array of numbers into percentages with the total value equaling 100%
body: <p>Hi I'm not sure how to title this but my problem is that I'm trying to find a way to map an array of numbers into an array of percentages constrained by a min and max percentage. In addition to that I would also like the total percentages to add up to 100%. Specifically this relates to NBA lottery odds. I would like to take </p>
  
  <p><code>nbaLotteryTeamsWinAmount2013 = [20, 21, 24, 25, 27, 28, 29, 29, 31, 33, 34, 34, 41, 43];</code></p>
  
  <p>and convert it into percentages ranging from .5% to 25%</p>
  
  <p><code>nbaLotteryOdds2013 = [.25, ..., 0.5];</code></p>
  
  <p>I have tried some ways of mapping it over but I get more of a linear transformation but I think I need a logrithmic scale or something else. Heres what I tried.</p>
  
  <pre><code>function offset(array, selectedMin, selectedMax) {
    var minValue = array.reduce(min);
    var maxValue = array.reduce(max);
    var selectedSpread = selectedMax - selectedMin;
  
    array = array.map(function(item) {
      return (item - minValue) / (maxValue - minValue) * selectedSpread + selectedMin;
    });
  
  }
  
  offset(nbaLotteryTeamsWinAmount2013, 0, 25);
  </code></pre>
  
  <p>The result of this was </p>
  
  <p><code>[0, 1.0869565217391304, 4.3478260869565215, 5.434782608695652, 7.608695652173914, 8.695652173913043, 9.782608695652174, 9.782608695652174, 11.956521739130435, 14.130434782608695, 15.217391304347828, 15.217391304347828, 22.82608695652174, 25]</code></p>
  
  <p>This resulted in a linear scale where the numbers looked to be on the same scale but didnt add up to the right amount.
  I'd like to do this in javascript (just because I know it better) but any language or hints would be appreciated.</p>