Skip to content

Commit

Permalink
reduce cyclo complexity with a boolean function
Browse files Browse the repository at this point in the history
  • Loading branch information
vaskoz committed Sep 7, 2018
1 parent d6d254f commit 02971da
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions day17/problem.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ func FindLongestAbsolutePathLength(fs string) int {
var isFile bool
var partStart, tabCount, maxLength int
for i, r := range fs {
if i-1 > 0 && fs[i-1] == '\t' && r != '\t' && r != '\n' {
if isNewStart(i, r, fs) {
partStart = i
} else if r == '.' {
isFile = true
Expand All @@ -21,11 +21,8 @@ func FindLongestAbsolutePathLength(fs string) int {
parts = parts[:pos]
}
parts = append(parts, fs[partStart:i])
if isFile {
len := len(strings.Join(parts, "/"))
if len > maxLength {
maxLength = len
}
if len := len(strings.Join(parts, "/")); isFile && len > maxLength {
maxLength = len
}
isFile = false
tabCount = 0
Expand All @@ -36,3 +33,7 @@ func FindLongestAbsolutePathLength(fs string) int {
}
return len(strings.Join(parts, "/"))
}

func isNewStart(i int, r rune, fs string) bool {
return i-1 > 0 && fs[i-1] == '\t' && r != '\t' && r != '\n'
}

0 comments on commit 02971da

Please sign in to comment.