-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
17 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,7 @@ | ||
Реализуйте функцию Reverse(slice []int) []int, которая принимает слайс целых чисел и возвращает новый слайс с элементами в обратном порядке. | ||
|
||
В Go нет встроенной функции удаления элемента из слайса. Реализуйте функцию `Remove(nums []int, i int) []int`, которая удаляет элемент по индексу `i` из слайса `nums`. Если приходит несуществующий индекс, то из функции возвращается исходный слайс. Порядок элементов может быть нарушен после удаления элемента. | ||
```go | ||
original := []int{1, 2, 3, 4, 5} | ||
Reverse(original) // [5 4 3 2 1] | ||
Reverse([]int{}) // [] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,15 @@ | ||
package solution | ||
|
||
import ( | ||
"sort" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestRemove(t *testing.T) { | ||
func TestReverse(t *testing.T) { | ||
a := assert.New(t) | ||
equalSlices(a, []int{1, 2}, Remove([]int{1, 2}, -1)) | ||
equalSlices(a, []int{1, 2}, Remove([]int{1, 2}, -5)) | ||
equalSlices(a, []int{2, 3}, Remove([]int{1, 2, 3}, 0)) | ||
equalSlices(a, []int{1, 2}, Remove([]int{1, 2, 3}, 2)) | ||
equalSlices(a, []int{1, 2, 3}, Remove([]int{1, 2, 3}, 3)) | ||
equalSlices(a, []int{1, 2, 3}, Remove([]int{1, 2, 3}, 5)) | ||
} | ||
|
||
func equalSlices(a *assert.Assertions, expected, actual []int) { | ||
sort.Ints(expected) | ||
sort.Ints(actual) | ||
a.Equal(expected, actual) | ||
a.Equal([]int{4, 3, 2, 1}, Reverse([]int{1, 2, 3, 4})) | ||
a.Equal([]int{}, Reverse([]int{})) | ||
a.Equal([]int{-1, -2, -3, -4}, Reverse([]int{-4, -3, -2, -1})) | ||
a.Equal([]int{3}, Reverse([]int{3})) | ||
} |