mirror of
https://github.com/wahyd4/redhat.git
synced 2026-08-09 04:25:53 +10:00
refactor
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user