Basic concept
I'm learning Go and I can't understand how to return data from an inner block of a function.
package main
import (
"fmt"
)
func main() {
fmt.Println("Hello, playground")
if isTrue("asasa") {
fmt.Println("isTrue is true")
}
}
func isTrue(s string) bool {
if s == "asasa" {
fmt.Println("it matches")
return true
}
}
https://play.golang.org/p/x6l29CNdg-o
How should I return a condition met inside a nested (even multiple time nested) block?
Real case scenario
func isUnique(h, c, L float64) bool {
for i, color := range usuedColors {
if color[0] == h && color[1] == c && color[2] == L {
fmt.Println("This color already exist!")
return false
} else {
return true
}
}
}
I receive a triple of values h, c, L
and I want to check if it is unique against a 2D slice where I've previously stored other triples.
I cycle through all the triple and if a match exist I want isUnique
to return as false, else true.