public/subjects/firstword
nprimo a15dcbf446 feat(firstword): add main.go 2024-06-27 22:38:26 +01:00
..
README.md docs(firstword): require a function instead of a program 2024-06-27 22:38:26 +01:00
main.go feat(firstword): add main.go 2024-06-27 22:38:26 +01:00

README.md

firstword

Instructions

Write a function that takes a string and return a string containing its first word, followed by a newline ('\n').

  • A word is a sequence of characters delimited by spaces or by the start/end of the argument.

Expected Function

func FirstWord(s string) string {
    // ...
}

Usage

Here is a possible way to test your function:

package main

import (
    "fmt"

    "piscine"
)

func main() {
    fmt.Print(piscine.FirstWord("hello there"))
    fmt.Print(piscine.FirstWord(""))
    fmt.Print(piscine.FirstWord("hello   .........  bye"))
}

And its output:

$ go run .
hello

hello
$