Skip to content

Commit fddfb40

Browse files
committed
chore: code cleanup
1 parent 13514ca commit fddfb40

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

dnacoder.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ func encodeTernaryToDNA(ternaryStr string) string {
5151

5252
// Decodes a DNA sequence (nucleotides) back to a ternary string (sequence of trits)
5353
func decodeDNAToTernary(dnaSeq string) (string, error) {
54-
var ternaryStr strings.Builder
5554
if len(dnaSeq) == 0 {
5655
return "", fmt.Errorf("empty DNA sequence")
5756
}
5857

58+
var ternaryStr strings.Builder
5959
previousNucleotide := byte('A')
60+
6061
for i := 0; i < len(dnaSeq); i++ {
6162
nextNucleotide := dnaSeq[i]
62-
6363
trit := reverseLookupTable[previousNucleotide][nextNucleotide]
6464
ternaryStr.WriteByte(byte(trit) + '0') // Convert to ASCII character
6565
previousNucleotide = nextNucleotide
@@ -70,18 +70,13 @@ func decodeDNAToTernary(dnaSeq string) (string, error) {
7070

7171
func encode(data []byte) string {
7272
ternaryStr := byteArrayToTernary([]byte(data))
73-
dnaSequence := encodeTernaryToDNA(ternaryStr)
74-
75-
return dnaSequence
73+
return encodeTernaryToDNA(ternaryStr)
7674
}
7775

7876
func decode(dnaSeq string) ([]byte, error) {
7977
ternaryStr, err := decodeDNAToTernary(dnaSeq)
8078
if err != nil {
8179
return nil, err
8280
}
83-
84-
byteArray := ternaryToByteArray(ternaryStr)
85-
86-
return byteArray, nil
81+
return ternaryToByteArray(ternaryStr), nil
8782
}

0 commit comments

Comments
 (0)