Beispiel #1
0
func scoreFilename(filename string) func(string, os.FileInfo, error) error {
	return func(path string, f os.FileInfo, err error) error {
		if !f.Mode().IsDir() {
			scores[path] = levenshtein.LevenshteinDistance(filename, path)
		}
		return nil
	}
}
Beispiel #2
0
func best(line string, lines []string) string {
	bestLine, bestScore := "", int(^uint(0)>>1) // largest int
	for _, testLine := range lines {
		score := levenshtein.LevenshteinDistance(line, testLine)
		if score < bestScore {
			bestLine, bestScore = testLine, score
		}
	}
	return bestLine
}