10
meros
8y

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)
}

Comments
  • 0
    I think santa should just give each person their presents and leave. He shouldn't care where everybody keeps their presents, or where is everyone siting in the living room.
  • 0
    But Santa isn't checking the list twice?!? Oh, i see it is not the song.
Add Comment