title: Performant fixed array range that changes
body: <p>This question is a little difficult to ask because I'm not quite sure what I'm asking. I know how it "should" work in my head.</p>
  
  <p><br>
  <strong>The problem:</strong></p>
  
  <p>I'm trying to create an index that uses an array of a fixed size, to implement a "range"-like lookup.</p>
  
  <p><br>
  <strong>Example:</strong></p>
  
  <p>Given an array length of <code>10</code>, and we push:</p>
  
  <p><code>[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]</code></p>
  
  <p>Everything works out! It fits properly.</p>
  
  <p>However, given an array length of <code>12</code>, and we push <code>24</code> items into it; </p>
  
  <p>we should receive something like:</p>
  
  <p><code>[2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24]</code></p>
  
  <p>Let's check whether to add the number <code>13</code> into it.</p>
  
  <p><code>[2, 4, 6, 8, 10, 12, 13, 14, 16, 18, 20, 22, 24]</code></p>
  
  <p>Okay, nothing to be done here. <code>13</code> falls between a valid range.. so we don't add it.</p>
  
  <p>Now let's add the number <code>28</code> into it.</p>
  
  <p><code>[2, 4, 6, 8, 10, 12, 13, 14, 16, 18, 20, 22, 24, 28]</code></p>
  
  <p>But now we have <code>25</code> items in it. I'm not sure what should happen here, but I'd imagine we want to re-arrange the array. We ideally want to <code>cap</code> the array to a fixed size, but need a way to create a new set of ranges.</p>
  
  <p>This should also work on the inverse, if we have an array of:</p>
  
  <p><code>[4, 7, 10]</code> - max size of <code>3</code></p>
  
  <p>and we add <code>1</code> to it, we need to create a new range.</p>
  
  <p><code>[1, 3, 10]</code></p>
  
  <p><br>
  I hope I've made this question clear.. I'm actually not sure if this is even the best way to accomplish my goals. All I know is that I want a fixed array size, and to be able to index the 'items' into it so I can use it as a range.</p>
  
  <p>The primary reason I'm concerned about performance is because this should be able to handle arrays of several hundred items (or even thousands).</p>
  
  <p>Similar questions here: <a href="https://stackoverflow.com/questions/42099244/split-javascript-array-of-numbers-into-ranges">#1</a>, <a href="https://stackoverflow.com/questions/52025608/interpolate-between-dates-given-known-index-range">#2</a></p>