31 lines
755 B
Go
31 lines
755 B
Go
|
package main
|
||
|
|
||
|
// helpers.go contains some helper functions for manipulating/processing data
|
||
|
// that doesn't really fit in elsewhere
|
||
|
|
||
|
// matchStringInSlice finds the closes match to 'ndl' in 'hay'
|
||
|
// It starts at the beginning of 'ndl' and matches letters in 'hay' until either
|
||
|
// we've matched the whole 'ndl' or there is only one result left
|
||
|
func matchStringInSlice(ndl string, hay []string) string {
|
||
|
var nextHay []string
|
||
|
|
||
|
for i := range ndl {
|
||
|
for _, p := range hay {
|
||
|
if p[i] == ndl[i] {
|
||
|
nextHay = append(hay, p)
|
||
|
}
|
||
|
}
|
||
|
// If we get here and there is only one parameter left, return it
|
||
|
hay = nextHay
|
||
|
if len(nextHay) == 1 {
|
||
|
break
|
||
|
}
|
||
|
// Otherwise, loop
|
||
|
nextHay = []string{}
|
||
|
}
|
||
|
if len(hay) == 0 {
|
||
|
return ""
|
||
|
}
|
||
|
return hay[0]
|
||
|
}
|