123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- var iterate = require('./lib/iterate.js')
- , initState = require('./lib/state.js')
- , terminator = require('./lib/terminator.js')
- ;
- module.exports = serialOrdered;
- module.exports.ascending = ascending;
- module.exports.descending = descending;
- function serialOrdered(list, iterator, sortMethod, callback)
- {
- var state = initState(list, sortMethod);
- iterate(list, iterator, state, function iteratorHandler(error, result)
- {
- if (error)
- {
- callback(error, result);
- return;
- }
- state.index++;
-
- if (state.index < (state['keyedList'] || list).length)
- {
- iterate(list, iterator, state, iteratorHandler);
- return;
- }
-
- callback(null, state.results);
- });
- return terminator.bind(state, callback);
- }
- function ascending(a, b)
- {
- return a < b ? -1 : a > b ? 1 : 0;
- }
- function descending(a, b)
- {
- return -1 * ascending(a, b);
- }
|