-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathget_updates.go
More file actions
37 lines (33 loc) · 839 Bytes
/
get_updates.go
File metadata and controls
37 lines (33 loc) · 839 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package main
type Updates struct {
New []Pokemon
}
func getPokemonUIDs(pokemons []Pokemon) []string {
var uids []string
for _, pokemon := range pokemons {
uids = append(uids, pokemon.UID())
}
return uids
}
func contains(arr []string, item string) bool {
for _, value := range arr {
if value == item {
return true
}
}
return false
}
func GetUpdates(previous, current []Pokemon) Updates {
previousUIDs := getPokemonUIDs(previous)
var currentUIDs []string
var new []Pokemon
for _, pokemon := range current {
// Only if the pokemon hasn't been seen yet
// And while we're at it, de-dupe the ones with the same UIDs
if !contains(previousUIDs, pokemon.UID()) && !contains(currentUIDs, pokemon.UID()) {
new = append(new, pokemon)
currentUIDs = append(currentUIDs, pokemon.UID())
}
}
return Updates{new}
}