{"ScriptPreparationCode":"var things = [\r\n { id: \u00223\u0022, finishedAt: 4 },\r\n { id: \u00225\u0022, finishedAt: null},\r\n { id: \u00222\u0022, finishedAt: 31 },\r\n { id: \u00226\u0022, finishedAt: 12 },\r\n { id: \u00227\u0022, finishedAt: 18 },\r\n { id: \u00228\u0022, finishedAt: 19 },\r\n { id: \u00229\u0022, finishedAt: 16 },\r\n { id: \u002210\u0022, finishedAt: 14 },\r\n { id: \u002211\u0022, finishedAt: 44 },\r\n { id: \u002212\u0022, finishedAt: 53 },\r\n { id: \u002213\u0022, finishedAt: null },\r\n { id: \u002214\u0022, finishedAt: 3 },\r\n { id: \u002215\u0022, finishedAt: 2 },\r\n { id: \u002216\u0022, finishedAt: 32 },\r\n { id: \u002217\u0022, finishedAt: 55 },\r\n { id: \u002218\u0022, finishedAt: 32 }, \r\n \t{ id: \u002219\u0022, finishedAt: 11 },\r\n { id: \u002220\u0022, finishedAt: 13 },\r\n { id: \u002221\u0022, finishedAt: 12 },\r\n { id: \u002222\u0022, finishedAt: 21 },\r\n { id: \u002223\u0022, finishedAt: 22 },\r\n { id: \u002224\u0022, finishedAt: 6 },\r\n { id: \u002225\u0022, finishedAt: 2 },\r\n { id: \u002226\u0022, finishedAt: 4 },\r\n { id: \u002227\u0022, finishedAt: 1 },\r\n { id: \u00221\u0022, finishedAt: 1 }\r\n];\r\n\r\nconsole.log(things.concat().sort(orderBy([\u0027finishedAt\u0027], [\u0027desc\u0027])));\r\n\r\nconsole.l\r\n \r\nfunction sortBy (key, cb) {\r\n if (!cb) cb = () =\u003E 0\r\n return (a, b) =\u003E \r\n (a[key] === null \u0026\u0026 b[key] === null) ? 0 \r\n : (a[key] === null) ? 1 \r\n : (b[key] === null) ? -1\r\n : (a[key] \u003E b[key]) ? 1\r\n : ((b[key] \u003E a[key]) ? -1 \r\n : cb(a, b))\r\n}\r\n\r\nfunction sortByDesc (key, cb) {\r\n if (!cb) cb = () =\u003E 0\r\nreturn (b, a) =\u003E \r\n (a[key] === null \u0026\u0026 b[key] === null) ? 0 \r\n : (a[key] === null) ? 1 \r\n : (b[key] === null) ? -1 \r\n : (a[key] \u003E b[key]) ? 1\r\n : ((b[key] \u003E a[key]) ? -1 \r\n : cb(b, a))\r\n}\r\n\r\nfunction orderBy (keys, orders) {\r\n let cb = () =\u003E 0\r\n keys.reverse()\r\n orders.reverse()\r\n for (const [i, key] of keys.entries()) {\r\n const order = orders[i]\r\n if (order == \u0027asc\u0027) {\r\n cb = sortBy(key, cb)\r\n } else if (order == \u0027desc\u0027) {\r\n cb = sortByDesc(key, cb)\r\n } else {\r\n throw new Error(\u0060Unsupported order \u0022${order}\u0022\u0060)\r\n }\r\n }\r\n return cb\r\n}\r\n","TestCases":[{"Name":"lodash OrderBy asc","Code":"_.orderBy(things,[\u0022finishedAt\u0022], [\u0022asc\u0022]);","IsDeferred":false},{"Name":"custom OrderBy asc","Code":"things.concat().sort(orderBy([\u0027finishedAt\u0027], [\u0027asc\u0027]))","IsDeferred":false},{"Name":"lodash OrderBy desc","Code":"_.orderBy(things,[\u0022finishedAt\u0022], [\u0022desc\u0022]);","IsDeferred":false},{"Name":"custom OrderBy desc","Code":"things.concat().sort(orderBy([\u0027finishedAt\u0027], [\u0027desc\u0027]))","IsDeferred":false}]}