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
Similar Kata:
Stats:
Created | Aug 11, 2017 |
Published | Aug 11, 2017 |
Warriors Trained | 657 |
Total Skips | 18 |
Total Code Submissions | 4531 |
Total Times Completed | 219 |
JavaScript Completions | 184 |
C# Completions | 41 |
Total Stars | 23 |
% of votes with a positive feedback rating | 90% of 72 |
Total "Very Satisfied" Votes | 59 |
Total "Somewhat Satisfied" Votes | 11 |
Total "Not Satisfied" Votes | 2 |
Total Rank Assessments | 10 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 7 kyu |