title: Check if value range is in array
body: <p><strong>What:</strong> I have an array that has angles from 0 to 360, a predefined range is entered, and a periodically updating input ranging from 0 to 360. I want to check if the input is within the the predefined range of the array.</p>
  
  <p><strong>Example</strong></p>
  
  <pre><code>array:
  array[0]=100, array[1]=40, array[2]=320, array[3]=60, etc....
  </code></pre>
  
  <p>What I need to do is to see if the input lets say</p>
  
  <pre><code>input:
  input=50;
  </code></pre>
  
  <p>is within a range of any of the values in the array</p>
  
  <pre><code>range:
  range=25;
  </code></pre>
  
  <p><strong>What I need code to do:</strong> 
  lower range = input-range &amp; upper range = input+range
  if values between the lower range and upper range exist in the array output the array number.</p>
  
  <p><strong>Completing the example:</strong> input-range=25   &amp;   input+range=75
  so if a value between 25 &amp; 75 exist in the array</p>
  
  <p><code>array[1]=40  &amp;  array[3]=60</code> are within that range.</p>
  
  <p>output the array key:</p>
  
  <pre><code>output[0]=1, output[1]=3
  </code></pre>
  
  <p><strong>Approach:</strong>
  Create a new nested array with the range added to and subtracted from the value in each array component. Then a for loop to check if the input is within any of the values.</p>
  
  <p><strong>Example Solution:</strong></p>
  
  <pre><code>var nodeArray=new Array(); 
  for(var i = 0; i&lt;array.length;i++){
  nodeArray[i].push(array[i]-range);
  nodeArray[i].push(array[i]+range);
  }
  
  then the function to check:
  for(var j=0;i&lt;array.length;i++){
  
  if ((input&gt;nodeArray[j][0])&amp;&amp;(input&lt;nodeArray[j][1])){
  alert("within range");
  }
  }
  </code></pre>
  
  <p><strong>Problem:</strong> I need a fast executing solution as time of execution is important to me and Im just curious if someone has a much improved idea on how to solve this problem.</p>
  
  <p><strong>Note:</strong> I also have not solved the fold over problem(350deg + 20 deg = 10 deg)</p>