|
|
@ -2,23 +2,31 @@ |
|
|
|
|
|
|
|
|
|
|
|
### Instructions |
|
|
|
### Instructions |
|
|
|
|
|
|
|
|
|
|
|
Écrire la fonction `ReverseRange` qui doit: |
|
|
|
Écrire un programme qui doit: |
|
|
|
|
|
|
|
|
|
|
|
- allouer (avec make()) une slice d'entiers. |
|
|
|
- Allouer (avec make()) une slice d'entiers. |
|
|
|
- le remplir avec des valeurs consécutives qui commencent à `end` et qui finissent à `start` (En incluant `start` et `end` !) |
|
|
|
|
|
|
|
- et qui retourne cette slice. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### Fonction attendue |
|
|
|
- Le remplir avec des valeurs consécutives qui commencent à `end` et qui finissent à `start` (En incluant `start` et `end` !) |
|
|
|
|
|
|
|
|
|
|
|
```go |
|
|
|
- Et qui affiche cette slice. |
|
|
|
func ReverseRange(start, end int) []int { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
Les erreurs doivent être gérées. |
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
Si le nombre d'arguments est différent de 2 le programme affiche un newline ("`\n`"). |
|
|
|
|
|
|
|
|
|
|
|
### Utilisation : |
|
|
|
### Utilisation : |
|
|
|
|
|
|
|
|
|
|
|
- Avec (1, 3) la fonction devra retourner une slice contenant 3, 2 et 1. |
|
|
|
```console |
|
|
|
- Avec (-1, 2) la fonction devra retourner une slice contenant 2, 1, 0 et -1. |
|
|
|
student@ubuntu:~/reverserange$ go build |
|
|
|
- Avec (0, 0) la fonction devra retourner une slice contenant 0. |
|
|
|
student@ubuntu:~/reverserange$ ./reverserange 1 3 |
|
|
|
- Avec (0, -3) la fonction devra retourner une slice contenant -3, -2, -1 et 0. |
|
|
|
[3 2 1] |
|
|
|
|
|
|
|
student@ubuntu:~/reverserange$ ./reverserange -1 2 | cat -e |
|
|
|
|
|
|
|
[2 1 0 -1]$ |
|
|
|
|
|
|
|
student@ubuntu:~/reverserange$ ./reverserange 0 0 |
|
|
|
|
|
|
|
[0] |
|
|
|
|
|
|
|
student@ubuntu:~/reverserange$ ./reverserange 0 -3 |
|
|
|
|
|
|
|
[-3 -2 -1 0] |
|
|
|
|
|
|
|
student@ubuntu:~/reverserange$ ./reverserange 0 nan | cat -e |
|
|
|
|
|
|
|
strconv.Atoi: parsing "nan": invalid syntax$ |
|
|
|
|
|
|
|
student@ubuntu:~/reverserange$ |
|
|
|
|
|
|
|
``` |
|
|
|