6 kyu

Portion of Array

184 of 219aweleshetu

Description:

You will be given an Array(a), starting position (i) and number of portion to return (n) . Your task is to return n portion of the array (a) starting from position (i ). The starting position could be negative, in that case you should start counting reverse direction till you get all your n portion. In case you can not find the exact n portion of elements counting from the starting position i or the starting position i is out of the index of the array, you should return -1 (throw an ArgumentOutOfRangeException in C#).

example:

function p([1,2,3,4],1,2)
 should return [2,3]
 
 how ?
 Array => [1,2,3,4]
           | | | |
 index =>  0 1 2 3
 portion     |_|   => [2,3]
 
function p([1,2,3,4],-1,2)
 should return [2,3]
 
 how ?
 Array => [1,  2,  3, 4]
           |   |   |  |
 index=>   -3 -2  -1  0
 portion=>     |___|      =>[2,3]    
 
function p([1],1,5)
 should return -1

how ? 
Array => [1]
          | 
index=>   0
required starting index =>1 , which does not exist so we return -1
Fundamentals

Stats:

CreatedAug 11, 2017
PublishedAug 11, 2017
Warriors Trained657
Total Skips18
Total Code Submissions4531
Total Times Completed219
JavaScript Completions184
C# Completions41
Total Stars23
% of votes with a positive feedback rating90% of 72
Total "Very Satisfied" Votes59
Total "Somewhat Satisfied" Votes11
Total "Not Satisfied" Votes2
Total Rank Assessments10
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • aweleshetu Avatar
  • Souzooka Avatar
  • dcieslak Avatar
  • hobovsky Avatar
  • dfhwze Avatar
Ad