- Source:
Examples
// array
var order = [];
var array = [4.2, 6.4, 6.1];
var iterator = function(num, done) {
setTimeout(function() {
order.push(num);
done(null, Math.floor(num));
}, num * 10);
};
async.groupBySeries(array, iterator, function(err, res) {
console.log(res); // { '4': [4.2], '6': [6.4, 6.1] }
console.log(order); // [4.2, 6.4, 6.1]
});
// array with index
var order = [];
var array = [4.2, 6.4, 6.1];
var iterator = function(num, index, done) {
setTimeout(function() {
order.push([num, index]);
done(null, Math.floor(num));
}, num * 10);
};
async.groupBySeries(array, iterator, function(err, res) {
console.log(res); // { '4': [4.2], '6': [6.4, 6.1] }
console.log(order); // [[4.2, 0], [6.4, 1], [6.1, 2]]
});
// object
var order = [];
var object = { a: 4.2, b: 6.4, c: 6.1 };
var iterator = function(num, done) {
setTimeout(function() {
order.push(num);
done(null, Math.floor(num));
}, num * 10);
};
async.groupBySeries(object, iterator, function(err, res) {
console.log(res); // { '4': [4.2], '6': [6.4, 6.1] }
console.log(order); // [4.2, 6.4, 6.1]
});
// object with key
var order = [];
var object = { a: 4.2, b: 6.4, c: 6.1 };
var iterator = function(num, key, done) {
setTimeout(function() {
order.push([num, key]);
done(null, Math.floor(num));
}, num * 10);
};
async.groupBySeries(object, iterator, function(err, res) {
console.log(res); // { '4': [4.2], '6': [6.4, 6.1] }
console.log(order); // [[4.2, 'a'], [6.4, 'b'], [6.1, 'c']]
});