10 examples of 'jquery sort' in JavaScript

Every line of 'jquery sort' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
20export function sort<T extends ISort>(array: T[]): T[] {
21 return array.sort((a, b) => (a.sortId === undefined || b.sortId === undefined) ? 0 : a.sortId - b.sortId);
22}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

229function sort(array) { return array.sort(sortFn); }
716function sort(array) {
717 return array.sort(sortFn);
718}
1export function sort(arr) {
2 return [...arr].sort((a, b) => a - b);
3}
2export function naturalSort(arr:any[], key:any):any[] {
3 let a, b, a1, b1, rx = /(\d+)|(\D+)/g, rd=/\d+/;
4 return arr.sort((as,bs) => {
5 a = String(eval('as.' + key)).toLowerCase().match(rx);
6 b = String(eval('bs.' + key)).toLowerCase().match(rx);
7 while(a.length && b.length) {
8 a1 = a.shift();
9 b1 = b.shift();
10 if(rd.test(a1) || rd.test(b1)) {
11 if(!rd.test(a1)) return 1;
12 if(!rd.test(b1)) return -1;
13 if(a1! = b1) return a1 - b1;
14 } else if(a1! = b1) {
15 return a1 > b1 ? 1 : -1;
16 }
17 }
18 return a.length - b.length;
19 });
20}
277function sort(arr) {
278 for (var i = 1; i < arr.length; i++) {
279 var tmp = arr[i]
280 var j = i
281 while (arr[j - 1] > tmp) {
282 arr[j] = arr[j - 1]
283 --j
284 }
285 arr[j] = tmp
286 }
287
288 return arr
289}
34export default function sortBy(array, sortType, order) {
35 let sortedData = [];
36
37 switch (sortType) {
38 case 'attributes.last_released_at':
39 sortedData = array.sort(releasedAtSort);
40 break;
41 case 'newReleases':
42 sortedData = array.sort(releasedAtSort).sort(newReleasesSort);
43 break;
44 case 'attributes.title':
45 sortedData = array.sort(titleSort);
46 break;
47 default:
48 sortedData = array.sort(newReleasesSort);
49 }
50
51 if (order === 'descending') { return sortedData.reverse(); }
52
53 return sortedData;
54}
50function sort(array, less) {
51 var result = [];
52 var currentPositions = [];
53 var current;
54 var position;
55 for (var i = 0; i < array.length; i += 1) {
56 current = array[i];
57 position = less[current];
58 if (currentPositions[current] === undefined) {
59 currentPositions[current] = position;
60 }
61 result[currentPositions[current]] = current;
62 currentPositions[current] += 1;
63 }
64 return result;
65}
118export function arraySort<T>(arr: T[], callbackfn?: (value1: T, value2: T) => number): T[] {
119 if (!callbackfn) {
120 //TODO: support native strings and number sorting
121 /* callbackfn = function (value1: string, value2: string) : number {
122 return value1.compare(value2);
123 }*/
124 }
125 return sortHelper(arr, callbackfn);
126}
54function sortByKey(array, key) {
55 return array.sort(function(a, b) {
56 var x = a[key];
57 var y = b[key];
58 return x < y ? -1 : x > y ? 1 : 0;
59 });
60}

Related snippets