Skip to content

Commit 74d9249

Browse files
committed
Updated Array.quicksort().
1 parent a1a34aa commit 74d9249

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

changes.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
- added: `F.restart()` for restarting app
1919
- added: `F.on('restart')`
2020
- added: quicksort algorithm for sorting arrays
21-
- added: `Array.quicksort(property_name, [asc])` for sorting arrays
21+
- added: `Array.quicksort(property_name, [asc], [maxlength])` for sorting arrays
2222
- added: `String.removeTags()` by @harry-stot
2323
- added: F.nosql(name) + NOSQL(name) --> alias for NoSQL embedded database (it can be used with e.g. SQL Agent)
2424
- added: modificators can handle `INSTALL('view', ...)`

utils.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4123,7 +4123,7 @@ Array.prototype.last = function(def) {
41234123
return item === undefined ? def : item;
41244124
};
41254125

4126-
Array.prototype.quicksort = Array.prototype.orderBy = function(name, asc) {
4126+
Array.prototype.quicksort = Array.prototype.orderBy = function(name, asc, maxlength) {
41274127

41284128
var length = this.length;
41294129
if (!length || length === 1)
@@ -4134,6 +4134,9 @@ Array.prototype.quicksort = Array.prototype.orderBy = function(name, asc) {
41344134
name = undefined;
41354135
}
41364136

4137+
if (maxlength === undefined)
4138+
maxlength = 3;
4139+
41374140
if (asc === undefined)
41384141
asc = true;
41394142

@@ -4169,7 +4172,7 @@ Array.prototype.quicksort = Array.prototype.orderBy = function(name, asc) {
41694172
// String
41704173
if (type === 1) {
41714174
if (va && vb)
4172-
return asc ? va.substring(0, 3).removeDiacritics().localeCompare(vb.substring(0, 3).removeDiacritics()) : vb.substring(0, 3).removeDiacritics().localeCompare(va.substring(0, 3).removeDiacritics());
4175+
return asc ? va.substring(0, maxlength).removeDiacritics().localeCompare(vb.substring(0, maxlength).removeDiacritics()) : vb.substring(0, maxlength).removeDiacritics().localeCompare(va.substring(0, maxlength).removeDiacritics());
41734176
return 0;
41744177
} else if (type === 2) {
41754178
if (va > vb)

0 commit comments

Comments
 (0)