Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
package main
import (
"log"
"strings"
)
type Present struct {
from string
to string
}
type Santa struct {
presents []Present
}
type Person struct {
Name string
Nice bool
Presents []Present
}
func (santa *Santa) givePresents(person Person) []Present {
result := []Present{}
if person.Nice != true {
return result
}
for _, present := range santa.presents {
if strings.Compare(present.to, person.Name) == 0 {
result = append(result, present)
}
}
return result
}
func main() {
santa := Santa{
[]Present{
{"devRant", "Alex"},
{"Johanna", "Alex"},
{"Alex", "devRant"},
{"Alex", "Johanna"},
},
}
persons := []Person{
{"Alex", true, []Present{}},
{"Johanna", true, []Present{}},
{"devRant", false, []Present{}},
}
for idx, person := range persons {
persons[idx].Presents = santa.givePresents(person)
}
log.Println(persons)
}
undefined
golang probablysuboptimal