GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 71dc20...f03d51 )
by Fedir
02:24
created

sorting/sorting.go   A

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 9
dl 0
loc 43
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A sorting.SortSliceByColumnIndexIntAsc 0 3 1
A sorting.SortSliceByColumnIndexIntDesc 0 3 1
A sorting.sortSliceByColumnIndexInt 0 13 4
A sorting.SortSliceByColumnIndexFloatDesc 0 10 3
1
// Copyright 2018 Fedir RYKHTIK. All rights reserved.
2
// Use of this source code is governed by the GNU GPL 3.0
3
// license that can be found in the LICENSE file.
4
5
package sorting
6
7
import (
8
	"log"
9
	"sort"
10
	"strconv"
11
)
12
13
func SortSliceByColumnIndexIntAsc(s [][]string, columnIndex int) [][]string {
0 ignored issues
show
introduced by
exported function SortSliceByColumnIndexIntAsc should have comment or be unexported
Loading history...
14
	s = sortSliceByColumnIndexInt(s, columnIndex, "asc")
15
	return s
16
}
17
18
func SortSliceByColumnIndexIntDesc(s [][]string, columnIndex int) [][]string {
0 ignored issues
show
introduced by
exported function SortSliceByColumnIndexIntDesc should have comment or be unexported
Loading history...
19
	s = sortSliceByColumnIndexInt(s, columnIndex, "desc")
20
	return s
21
}
22
23
func sortSliceByColumnIndexInt(s [][]string, columnIndex int, direction string) [][]string {
24
	if columnIndex == 0 {
25
		log.Fatalf("Error occurred. Please check map of columns indexes")
26
	}
27
	sort.Slice(s, func(i, j int) bool {
28
		firstCellValue, _ := strconv.Atoi(s[i][columnIndex])
29
		secondCellValue, _ := strconv.Atoi(s[j][columnIndex])
30
		if direction == "desc" {
31
			return firstCellValue > secondCellValue
32
		}
33
		return firstCellValue < secondCellValue
34
	})
35
	return s
36
}
37
38
func SortSliceByColumnIndexFloatDesc(s [][]string, columnIndex int) [][]string {
0 ignored issues
show
introduced by
exported function SortSliceByColumnIndexFloatDesc should have comment or be unexported
Loading history...
39
	if columnIndex == 0 {
40
		log.Fatalf("Error occurred. Please check map of columns indexes")
41
	}
42
	sort.Slice(s, func(i, j int) bool {
43
		firstCellValue, _ := strconv.ParseFloat(s[i][columnIndex], 32)
44
		secondCellValue, _ := strconv.ParseFloat(s[j][columnIndex], 32)
45
		return firstCellValue > secondCellValue
46
	})
47
	return s
48
}
49