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

sort.js ➔ byDateAsc   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
c 1
b 0
f 0
nc 3
dl 0
loc 10
rs 9.4285
nop 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
}