Completed
Push — master ( bdfcbe...91ed9c )
by
unknown
02:02
created

src/cli/core/utils/sort.js   A

Complexity

Total Complexity 8
Complexity/F 2.67

Size

Lines of Code 40
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
wmc 8
c 1
b 0
f 0
nc 1
mnd 2
bc 8
fnc 3
dl 0
loc 40
rs 10
bpm 2.6666
cpm 2.6666
noi 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A sort.js ➔ byDateAsc 0 10 3
A sort.js ➔ shuffle 0 18 2
1
export function byDateDesc(a, b) {
2
  var dateA = new Date(a.date)
3
  var dateB = new Date(b.date)
4
  if(dateA < dateB) {
5
    return 1
6
  }else if(dateA > dateB) {
7
    return -1
8
  }
9
  return 0
10
}
11
12
export function shuffle(array) {
13
  var currentIndex = array.length, temporaryValue, randomIndex
14
15
  // While there remain elements to shuffle...
16
  while (0 !== currentIndex) {
17
18
    // Pick a remaining element...
19
    randomIndex = Math.floor(Math.random() * currentIndex)
20
    currentIndex -= 1
21
22
    // And swap it with the current element.
23
    temporaryValue = array[currentIndex]
24
    array[currentIndex] = array[randomIndex]
25
    array[randomIndex] = temporaryValue
26
  }
27
28
  return array
29
}
30
31
export function byDateAsc(a, b) {
32
  var dateA = new Date(a.date)
33
  var dateB = new Date(b.date)
34
  if(dateA > dateB) {
35
    return 1
36
  }else if(dateA < dateB) {
37
    return -1
38
  }
39
  return 0
40
}