798b750c0efe8758847ea9f232954abfdaea70604a3ce12acfe34c0f5e4a6d95.json raw
1 {"ast":null,"code":"if (!Array.prototype.empty) {\n Array.prototype.empty = function () {\n return this.length === 0;\n };\n}\nif (!Array.prototype.sortBy) {\n Array.prototype.sortBy = function (keyFunction, order) {\n if (this.length === 0) {\n return [];\n }\n // determine sort order (asc or desc / asc is default)\n let asc = true;\n if (order === 'desc') {\n asc = false;\n }\n const arrayClone = Array.from(this);\n const firstSortProperty = keyFunction(arrayClone[0]);\n if (typeof firstSortProperty === 'string') {\n // string in-place sort\n arrayClone.sort((a, b) => {\n if (asc) {\n return ('' + keyFunction(a)).localeCompare(keyFunction(b));\n }\n return ('' + keyFunction(b)).localeCompare(keyFunction(a));\n });\n } else if (typeof firstSortProperty === 'number') {\n // number in-place sort\n if (asc) {\n arrayClone.sort((a, b) => Number(keyFunction(a)) - Number(keyFunction(b)));\n } else {\n arrayClone.sort((a, b) => Number(keyFunction(b)) - Number(keyFunction(a)));\n }\n } else {\n throw new Error('sortBy is not implemented for that type!');\n }\n return arrayClone;\n };\n}\nif (!Array.prototype.groupBy) {\n Array.prototype.groupBy = function (fn, reduceFn) {\n const result = new Map();\n const distinctKeys = new Set(this.map(x => fn(x)));\n for (const distinctKey of distinctKeys) {\n const distinctKeyItems = this.filter(x => fn(x) === distinctKey);\n result.set(distinctKey, reduceFn(distinctKeyItems));\n }\n return result;\n };\n}\nexport {};","map":null,"metadata":{},"sourceType":"module","externalDependencies":[]}