From aef8baee0a38fa14d46fc6542fcd317f6be21b99 Mon Sep 17 00:00:00 2001 From: Anna Wiggins Date: Tue, 6 Apr 2021 04:17:49 +0000 Subject: [PATCH] Use canonical names for the letters, and fix comparisons where one letter's name is a strict initial substring of another. --- alphabetter.go | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/alphabetter.go b/alphabetter.go index f1396c4..4f0a4fa 100644 --- a/alphabetter.go +++ b/alphabetter.go @@ -10,31 +10,31 @@ import ( ) var SPELLINGS = map[rune]string{ - 'A': "AY", + 'A': "A", 'B': "BEE", - 'C': "SEE", + 'C': "CEE", 'D': "DEE", - 'E': "EE", - 'F': "EFF", + 'E': "E", + 'F': "EF", 'G': "GEE", 'H': "AITCH", - 'I': "EYE", + 'I': "I", 'J': "JAY", 'K': "KAY", - 'L': "ELL", - 'M': "EMM", - 'N': "ENN", - 'O': "OH", + 'L': "EL", + 'M': "EM", + 'N': "EN", + 'O': "O", 'P': "PEE", 'Q': "CUE", - 'R': "ARR", + 'R': "AR", 'S': "ESS", 'T': "TEE", - 'U': "EWE", + 'U': "U", 'V': "VEE", - 'W': "DOUBLE EWE", - 'X': "ECKS", - 'Y': "WHY", + 'W': "DOUBLE U", + 'X': "EX", + 'Y': "WYE", 'Z': "ZEE", } @@ -114,7 +114,11 @@ func sortAlphabet(alphabet []rune) []rune { j_index := -1 k := 0 - for k = 0; k < len(i_spelling) && k < len(j_spelling); k++ { + for k = 0; ; k++ { + if k >= len(i_spelling) || k >= len(j_spelling) { + return len(i_spelling) < len(j_spelling) + } + i_index = findIndex(alphabet, rune(i_spelling[k])) j_index = findIndex(alphabet, rune(j_spelling[k]))