mirror of
https://github.com/cryptpad/cryptpad.git
synced 2026-09-14 11:05:41 +05:00
perf(sortify): don’t redefine isNumericalExpr everytime
+ style
This commit is contained in:
parent
7528aeecbb
commit
145a51bd43
@ -857,6 +857,7 @@ const factory = (NaclUtil) => {
|
||||
};
|
||||
/* End of code copied from saferphore */
|
||||
|
||||
const isNumericalExpr = /^(0|[1-9]\d*)$/;
|
||||
const sortKeys = obj => {
|
||||
if (Array.isArray(obj)) {
|
||||
return obj.map(sortKeys);
|
||||
@ -865,13 +866,13 @@ const factory = (NaclUtil) => {
|
||||
let numeric = [];
|
||||
let nonNumeric = [];
|
||||
Object.keys(obj).forEach(key => {
|
||||
if (/^(0|[1-9]\d*)$/.test(key)) {
|
||||
if (isNumericalExpr.test(key)) {
|
||||
numeric.push(+key);
|
||||
} else {
|
||||
nonNumeric.push(key);
|
||||
}
|
||||
});
|
||||
return numeric.sort((a,b) => a - b).concat(nonNumeric.sort()).reduce((result, key) => {
|
||||
return numeric.sort((a, b) => a - b).concat(nonNumeric.sort()).reduce((result, key) => {
|
||||
result[key] = sortKeys(obj[key]);
|
||||
return result;
|
||||
}, {});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user