packagefind// MissingLetter indicates what the missing character is in a ordered sequence of charactersfuncMissingLetter(chars[]rune)rune{varlastintfor_,r:=rangechars{iflast!=0&&int(r)-last>1{returnrune(r-1)}last=int(r)}returnrune(last)}
missing_letter_test.go
packagefindimport"testing"typetestCasestruct{descriptionstringinput[]runeexpectedrune}funcTestMissingLetter(t*testing.T){testCases:=[]testCase{{"two characters",[]rune{'A','C'},'B',},{"dev-to example one",[]rune{'a','b','c','d','f'},'e',},{"dev-to example two",[]rune{'O','Q','R','S'},'P',},}for_,test:=rangetestCases{ifresult:=MissingLetter(test.input);result!=test.expected{t.Fatalf("FAIL: %s - MissingLetter(%+v): %v - expected %v",test.description,test.input,result,test.expected)}t.Logf("PASS: %s",test.description)}}
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Time to Go find the missing letter!
missing_letter.go
missing_letter_test.go