mirror of https://github.com/01-edu/public.git
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.
50 lines
934 B
50 lines
934 B
2 years ago
|
## iscapitalized
|
||
2 years ago
|
|
||
2 years ago
|
### Instructions
|
||
2 years ago
|
|
||
2 years ago
|
Write a function `IsCapitalized` that takes a `string` as an argument and returns `true` if each word in the `string` begins with either an uppercase letter or a non-alphabetic character.
|
||
|
|
||
|
- If any of the words begin with a lowercase letter return `false`.
|
||
|
- If the `string` is empty return `false`.
|
||
2 years ago
|
|
||
|
### Expected function
|
||
|
|
||
|
```go
|
||
2 years ago
|
func IsCapitalized(s string) bool {
|
||
2 years ago
|
|
||
|
}
|
||
|
```
|
||
|
|
||
|
### Usage
|
||
2 years ago
|
Here is a possible program to test your function:
|
||
2 years ago
|
|
||
|
```go
|
||
|
package main
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
2 years ago
|
"piscine"
|
||
2 years ago
|
)
|
||
|
|
||
|
func main() {
|
||
2 years ago
|
fmt.Println(piscine.IsCapitalized("Hello! How are you?"))
|
||
|
fmt.Println(piscine.IsCapitalized("Hello How Are You"))
|
||
|
fmt.Println(piscine.IsCapitalized("Whats 4this 100K?"))
|
||
|
fmt.Println(piscine.IsCapitalized("Whatsthis4"))
|
||
|
fmt.Println(piscine.IsCapitalized("!!!!Whatsthis4"))
|
||
|
fmt.Println(piscine.IsCapitalized(""))
|
||
2 years ago
|
}
|
||
|
```
|
||
|
|
||
2 years ago
|
And its output:
|
||
2 years ago
|
|
||
|
```console
|
||
|
$ go run .
|
||
|
false
|
||
|
true
|
||
|
true
|
||
|
true
|
||
2 years ago
|
true
|
||
|
false
|
||
|
```
|