Function
orderArrayByArrayWithKey
(array: any[], order: string[], key: string)
Source from the content-addressed store, hash-verified
| 69 | |
| 70 | |
| 71 | export const orderArrayByArrayWithKey = (array: any[], order: string[], key: string) =>{ |
| 72 | |
| 73 | return array.sort( function (a, b) { |
| 74 | const A = order.indexOf(a[key]), B = order.indexOf(b[key]); |
| 75 | |
| 76 | if (A > B) { |
| 77 | if (A != -1 && B == -1) { |
| 78 | return -1 |
| 79 | } |
| 80 | return 1; |
| 81 | } else { |
| 82 | if (B != -1 && A == -1) { |
| 83 | return 1 |
| 84 | } |
| 85 | return -1; |
| 86 | } |
| 87 | |
| 88 | }); |
| 89 | |
| 90 | }; |
Tested by
no test coverage detected