| Total Complexity | 8 |
| Complexity/F | 2.67 |
| Lines of Code | 40 |
| Function Count | 3 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 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 | } |