|
- 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);
- }
|