This commit is contained in:
2020-01-14 11:53:47 +11:00
parent 0f70989d1e
commit a1327ef122
+9 -7
View File
@@ -4,13 +4,7 @@ import "fmt"
// Output print out the result with target format
func (fa *FileAnalyser) Output(topLines int) []string {
var resultRows []dataRow
if len(fa.dataRows) < 10 {
resultRows = fa.dataRows[0:len(fa.dataRows)]
} else {
resultRows = fa.dataRows[0:topLines]
}
resultRows := fa.getResultRows(topLines)
reverseDataRows(resultRows)
@@ -22,6 +16,14 @@ func (fa *FileAnalyser) Output(topLines int) []string {
return outputArray
}
func (fa *FileAnalyser) getResultRows(topLines int) []dataRow {
if len(fa.dataRows) < topLines {
return fa.dataRows[0:len(fa.dataRows)]
}
return fa.dataRows[0:topLines]
}
func reverseDataRows(rows []dataRow) {
for index := len(rows)/2 - 1; index >= 0; index-- {
opposite := len(rows) - 1 - index