Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Exercise: Create a unique list of values

Given a list of strings, create a list of unique values sorted by abc.

package main

import "fmt"

func main() {
	// input
	fruits := []string{"grape", "banana", "mango", "nut", "orange", "peach", "apple", "nut", "banana", "apple", "mango"}
	fmt.Println(fruits)

	// expected output:
	uniqueFruites := []string{"apple", "banana", "grape", "mango", "nut", "orange", "peach"}
	fmt.Println(uniqueFruites)
}