title: Get the N elements from array based on the position
body: <p>I want a function that returns the sub array which takes a position &amp; the no. of elements I want. I think there may be some algorithm to find the pivot point or something &amp; from that I can get the sub array, but I totally forgot it.</p>
  
  <pre><code>Example: a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
  I want 6 elements
  if position = 0, then I want [1, 2, 3, 4, 5, 6]
  if position = 1, then [1, 2, 3, 4, 5, 6]
  if position = 2, then [1, 2, 3, 4, 5, 6]
  if position = 3, then [1, 2, 3, 4, 5, 6]
  if position = 4, then [2, 3, 4, 5, 6, 7]
  if position = 5, then [3, 4, 5, 6, 7, 8]
  if position = 6, then [4, 5, 6, 7, 8, 9]
  if position = 7, then [5, 6, 7, 8, 9, 10]
  if position = 8, then [5, 6, 7, 8, 9, 10]
  if position = 9, then [5, 6, 7, 8, 9, 10]
  simply get the middle of N elements based on the position I pass.
  </code></pre>
  
  <p>I can write up my own <code>loop</code> which will contain multiple <code>if-else</code> conditions to get it done. But I feel there may be some easy way to do it.</p>
  
  <p>I didnt include my incomplete code snippet because I strongly feel there must be some algorithm to do this.</p>