Problem
Given an array numbers consisting of natural numbers and two integers start and end, write a function solution that returns a new array containing elements from numbers starting at index start and ending at index end.
Constraints
- Each element in
numbersis a natural number not exceeding 20. numbersis not empty, and its length does not exceed 100.startandendare integers between 0 and the length ofnumbers, inclusive.startis always less than or equal toend.
Test Case
| Test Case Number | numbers | start | end | return |
|---|---|---|---|---|
| 1 | [1] | 0 | 0 | [1] |
| 2 | [1, 2, 3, 4, 5] | 1 | 3 | [2, 3, 4] |
| 3 | [4, 5, 6] | 0 | 2 | [4, 5, 6] |
Explanation for Test Case 1
- Given
numbers = [1],start = 0, andend = 0, selecting only the 0th index results in[1].
Explanation for Test Case 2
- Given
numbers = [1, 2, 3, 4, 5],start = 1, andend = 3, selecting from the 1st to 3rd index results in[2, 3, 4].
Explanation for Test Case 3
- Given
numbers = [4, 5, 6],start = 0, andend = 2, selecting from the 0th to 2nd index results in[4, 5, 6].