Create range(s) from single number
<p><strong>SOLVED</strong>
@Jeff and @Eric, thanks a lot. In the end I have to go with Eric's solution with a minor change.</p>

<pre><code>for(; i+4&lt;=n; i+=4)
</code></pre>

<p>This how I'm going to use it:</p>

<pre><code>function findRange(n,div)
{
var odd =1&amp;n;
var i = 0;
var ranges = [];

  for(; i + div&lt;= n; i+=div) 
  {
     ranges.push([i+1, i+div]); // in array 1-4 / 5-8 etc
     // or in side cases the 2nd part of the array contains the remainder
     ranges.push([i+1, n]); // 1-16,5-16,9-16,etc
     ranges.push([i+div, n]); // 4-16,8-16,12-16,etc

     if(odd === 1)
     {
        ranges.push([i+div+1, n]); // in case of input 7 creates array 5-7
     }
  }

return ranges;
}
console.log(findRange(16,4)); 
</code></pre>

<h2>This solution answers the following questions</h2>

<p>Question 1:<br/> How to create the ranges (1-4, 5-8, 9-12, 13-16) from f.e. the number 16</p>

<p>Question 4:<br/> How to find the 1st and last number from that range (1 and 4, 5 and 8 etc)</p>

<p>Question 2:<br/> How to deal with the situation where the input number is for example 17. This would give these ranges 1-4, 5-8, 9-12, 13-16 and a remaining number 17.</p>

<h2>Original question below.</h2>

<p>I need to know how to create a range from a single number where the single number is variable. The range always needs to fall within 4 positions. Per range I need to know the first and last number. Per range I need to know the numbers in between.</p>

<p>For example: the single (input) number is 16, which gives the following 4 ranges of 4 (1-4, 5-8, 9-12, 13-16).</p>

<p>Question 1:<br/> How to create the ranges (1-4, 5-8, 9-12, 13-16) from f.e. the number 16</p>

<p>Question 2:<br/> How to deal with the situation where the input number is for example 17. This would give these ranges 1-4, 5-8, 9-12, 13-16 and a remaining number 17.</p>

<p>Question 3:<br/> How to deal with the situation where the input number is 3 so the range is 1-3</p>

<hr>

<p><em>Questions below are optional because these answers can probably be found here on stack.</em></p>

<p>Question 4:<br/> How to find the 1st and last number from that range (1 and 4, 5 and 8 etc)</p>

<p>Question 5:<br/> How to find the numbers in the range (range1: 1,2,3,4 | range2: 5,6,7,8 etc) per range.</p>

<hr>

<p>I haven't really tried anything yet because don't know how to get to the first step at all.</p>

<p>One thing I tried was using % (modulus) but that wasn't the answer. I tried this:</p>

<pre><code>var x=16;

for(var i=0; i&lt;=x; i++)
{
  for(i % 4 === 0)
  {
    return i;
  }
}
</code></pre>

<p>it gave me 4,8,12,16 which is nice but far from what I'm looking for. I'm very tired of breaking my head about this. I'm very curious what would be the solution for this.</p>

<p>I'm not sure if it's allowed to ask questions this way. But since they are all related to the range I thought it would be good to be as specific as possible about what I'm looking for.</p>
