Показать сообщение отдельно
  #3 (permalink)  
Старый 22.03.2015, 01:19
Профессор
Отправить личное сообщение для Telnet Посмотреть профиль Найти все сообщения от Telnet
 
Регистрация: 21.02.2011
Сообщений: 160

Сделал может кому пригодится
// Функции сортировки по id 
function sIdAsc(a, b) {
    if (a[0] > b[0]) return 1;
    else if (a[0] < b[0]) return -1; else return 0;
}
function sIdDesc(a, b) {
    if (a[0] < b[0]) return 1;
    else if (a[0] > b[0]) return -1; else return 0;
}
// Функции сортировки по дате
function sDateAsc(a, b) {
    if (a[1] > b[1]) return 1;
    else if (a[1] < b[1]) return -1;
    else return 0;
}
function sDateDesc(a, b) {
    if (a[1] < b[1]) return 1;
    else if (a[1] > b[1]) return -1;
    else return 0;
}
// Функции сортировки по имени
function sNameAsc(a, b) {
    if (a[2] > b[2]) return 1;
    else if (a[2] < b[2]) return -1;
    else return 0;
}
function sNameDesc(a, b) {
    if (a[2] < b[2]) return 1;
    else if (a[2] > b[2]) return -1;
    else return 0;
}
console.log('Фильт по id убывание');
sorting.sort(sIdAsc);
console.log(sorting.join('\n'));
console.log('Фильт по Date убывание');
sorting.sort(sDateAsc);
console.log(sorting.join('\n'));
console.log('Фильт по Name убывание');
sorting.sort(sNameAsc);
console.log(sorting.join('\n'));
console.log('Фильт по id возрастание');
sorting.sort(sIdDesc);
console.log(sorting.join('\n'));
console.log('Фильт по Date возрастание');
sorting.sort(sDateDesc);
console.log(sorting.join('\n'));
console.log('Фильт по Name возрастание');
sorting.sort(sNameDesc);
console.log(sorting.join('\n'));
console.log('------------------------');

То что имеем на выходе

Изначальный массив
53,2015-03-18 09:53:33,Super User
63,2015-03-21 17:30:00,Super User
53,2015-03-18 09:53:33,Super User
62,2015-03-21 10:52:41,test
56,2015-03-18 15:57:33,Super User
61,2015-03-19 18:53:16,Super User
51,2015-03-18 09:16:00,Super User
60,2015-03-19 18:53:04,Super User
57,2015-03-18 16:00:40,Super User
58,2015-03-18 16:01:46,Super User
59,2015-03-18 16:48:52,Super User
Фильт по id убывание
51,2015-03-18 09:16:00,Super User
53,2015-03-18 09:53:33,Super User
53,2015-03-18 09:53:33,Super User
56,2015-03-18 15:57:33,Super User
57,2015-03-18 16:00:40,Super User
58,2015-03-18 16:01:46,Super User
59,2015-03-18 16:48:52,Super User
60,2015-03-19 18:53:04,Super User
61,2015-03-19 18:53:16,Super User
62,2015-03-21 10:52:41,test
63,2015-03-21 17:30:00,Super User
Фильт по Date убывание
51,2015-03-18 09:16:00,Super User
53,2015-03-18 09:53:33,Super User
53,2015-03-18 09:53:33,Super User
56,2015-03-18 15:57:33,Super User
57,2015-03-18 16:00:40,Super User
58,2015-03-18 16:01:46,Super User
59,2015-03-18 16:48:52,Super User
60,2015-03-19 18:53:04,Super User
61,2015-03-19 18:53:16,Super User
62,2015-03-21 10:52:41,test
63,2015-03-21 17:30:00,Super User
Фильт по Name убывание
58,2015-03-18 16:01:46,Super User
51,2015-03-18 09:16:00,Super User
53,2015-03-18 09:53:33,Super User
56,2015-03-18 15:57:33,Super User
57,2015-03-18 16:00:40,Super User
53,2015-03-18 09:53:33,Super User
59,2015-03-18 16:48:52,Super User
60,2015-03-19 18:53:04,Super User
61,2015-03-19 18:53:16,Super User
63,2015-03-21 17:30:00,Super User
62,2015-03-21 10:52:41,test
Фильт по id возрастание
63,2015-03-21 17:30:00,Super User
62,2015-03-21 10:52:41,test
61,2015-03-19 18:53:16,Super User
60,2015-03-19 18:53:04,Super User
59,2015-03-18 16:48:52,Super User
58,2015-03-18 16:01:46,Super User
57,2015-03-18 16:00:40,Super User
56,2015-03-18 15:57:33,Super User
53,2015-03-18 09:53:33,Super User
53,2015-03-18 09:53:33,Super User
51,2015-03-18 09:16:00,Super User
Фильт по Date возрастание
63,2015-03-21 17:30:00,Super User
62,2015-03-21 10:52:41,test
61,2015-03-19 18:53:16,Super User
60,2015-03-19 18:53:04,Super User
59,2015-03-18 16:48:52,Super User
58,2015-03-18 16:01:46,Super User
57,2015-03-18 16:00:40,Super User
56,2015-03-18 15:57:33,Super User
53,2015-03-18 09:53:33,Super User
53,2015-03-18 09:53:33,Super User
51,2015-03-18 09:16:00,Super User
Фильт по Name возрастание
62,2015-03-21 10:52:41,test
58,2015-03-18 16:01:46,Super User
61,2015-03-19 18:53:16,Super User
60,2015-03-19 18:53:04,Super User
59,2015-03-18 16:48:52,Super User
63,2015-03-21 17:30:00,Super User
57,2015-03-18 16:00:40,Super User
56,2015-03-18 15:57:33,Super User
53,2015-03-18 09:53:33,Super User
53,2015-03-18 09:53:33,Super User
51,2015-03-18 09:16:00,Super User
------------------------
Ответить с цитированием