Problem
Given an array numbers consisting of integer elements and a natural number step representing an interval, write a function solution that selects elements from numbers starting at index 0 and skipping step elements at a time, returning the resulting array.
Constraints
- Each element in
numbersis an integer with an absolute value not exceeding 500. numbersis not empty, and its length does not exceed 100.stepdoes not exceed the length ofnumbers.
Test Case
| Test Case Number | numbers | step | return |
|---|---|---|---|
| 1 | [1, 2, 3, 4] | 1 | [1, 2, 3, 4] |
| 2 | [1, 2, 3, 4] | 2 | [1, 3] |
| 3 | [1, 2, 3, 4] | 4 | [1] |
Explanation for Test Case 1
- Starting from index 0 and skipping by 1, the selected elements are
[1, 2, 3, 4].
Explanation for Test Case 2
- Starting from index 0 and skipping by 2, the selected elements are
[1, 3].
Explanation for Test Case 3
- Starting from index 0 and skipping by 4, the selected element is
[1].