MCPcopy Create free account
hub / github.com/Make-md/makemd / orderArrayByArrayWithKey

Function orderArrayByArrayWithKey

src/shared/utils/array.ts:71–90  ·  view source on GitHub ↗
(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 };

Callers 1

allSpacesMethod · 0.90

Calls 1

sortMethod · 0.80

Tested by

no test coverage detected