forked from root/public
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1.3 KiB
1.3 KiB
printandmiss
Instructions
Write a function called PrintAndMiss()
that takes a string
and an int
as an argument. The function should move through the string
in sets determined by the int
, printing the first set, omitting the second, printing the third, and so on, in a 'print' and 'miss' fashion until the end of the string
is reached. Return a string
containing the printed characters.
- If the
string
is empty or theint
is negative returnInvalid Output
followed by newline\n
. - If the
int
is0
return thestring
followed by a newline\n
.
Expected function
func PrintAndMiss(arg string, num int) string {
}
Usage
Here is a possible program to test your function:
package main
import (
"fmt"
"piscine"
)
func main() {
fmt.Print(piscine.PrintAndMiss("123456789", 3))
fmt.Print(piscine.PrintAndMiss("abcdefghijklmnopqrstuvwyz", 3))
fmt.Print(piscine.PrintAndMiss("", 3))
fmt.Print(piscine.PrintAndMiss("hello you all ! ", 0))
fmt.Print(piscine.PrintAndMiss("what is your name?", 0))
fmt.Print(piscine.PrintAndMiss("go Exercise Print and Miss", -5))
}
And its output:
$ go run . | cat -e
123789$
abcghimnostuz$
Invalid Output$
hello you all ! $
what is your name?$
Invalid Output$