title: Mapping array of integers to an array of integres
body: <p>I have a slider that has the following raw snap points:</p>
  
  <pre><code>[-100, -200, -300, -400, -500, -600]
  </code></pre>
  
  <p>And I would like to convert the sliding value to match the following snap points:</p>
  
  <pre><code>[0, 5, 10, 25, 50, 100]
  </code></pre>
  
  <ul>
  <li><p>A raw value in <code>[-100, -200)</code> should be mapped to a value in <code>[0, 5)</code></p></li>
  <li><p>A raw value in <code>[-200, -300)</code> should be mapped to a value in <code>[5, 10)</code></p></li>
  <li><p>A raw value in <code>[-300, -400)</code> should be mapped to a value in <code>[10, 25)</code></p></li>
  </ul>
  
  <p>And so on ..</p>
  
  <p>How can I achieve that?</p>
  
  <p><strong>Edit: added my attempt (different raw values though)</strong></p>
  
  <pre><code>// sliderValue is an integer obtained from the slider
  
  const base = -70
  const offset = -80
  
  const limits = [
    base + offset * 0, // -70
    base + offset * 1, // -150
    base + offset * 2, // -230
    base + offset * 3, // -310
    base + offset * 4, // -390
    base + offset * 5, // -470
  ]
  
  const points = [0, 5, 10, 25, 50, 100]
  
  // I can't even begin to make sense of this
  // don't know I came up with it, but it works ¯\_(ツ)_/¯
  if (sliderValue &lt;= limits[4]) {
    percentage = scaleValue(sliderValue, limits[4], limits[5], 50, 100)
  } else if (sliderValue &lt;= limits[3]) {
    percentage = scaleValue(sliderValue, limits[3], limits[4], 25, 50)
  } else if (sliderValue &lt;= limits[2]) {
    percentage = scaleValue(sliderValue, limits[2], limits[3], 10, 25)
  } else if (sliderValue &lt;= limits[1]) {
    percentage = scaleValue(sliderValue, limits[1], limits[2], 5, 10)
  } else if (sliderValue &lt;= limits[0]) {
    percentage = scaleValue(sliderValue, limits[0], limits[1], 0, 5)
  }
  
  console.log(percentage)
  
  // ..
  
  function scaleValue(num, in_min, in_max, out_min, out_max) {
    return ((num - in_min) * (out_max - out_min)) / (in_max - in_min) + out_min
  }
  </code></pre>