0.0.2 • Published 10 years ago

dlutil v0.0.2

Weekly downloads
1
License
-
Repository
github
Last release
10 years ago

dlutil

Node.js utility functions.

Most functions have synchronous and asynchronous versions. All asynchronous versions of methods have Async appended to the function name.

partition

Partition a list according to keys returned from an iterator function.

var l = [1, 2, 3, 4, 5];
function evenOdd(n) {
	return (n % 2 == 0) ? 'even' : 'odd';
}
var partitioned = dlutil.partition(l, evenOdd);
/*
partitioned = {
	even: [2, 4],
	odd: [1, 3, 5]
}
*/

And the async version

var l = [1, 2, 3, 4, 5];
function evenOdd(n, next) {
	return next(null, (n % 2 == 0) ? 'even' : 'odd');
}
dlutil.partitionAsync(l, evenOdd, function(err, partitioned) {
	/*
	partitioned = {
		even: [2, 4],
		odd: [1, 3, 5]
	}
	*/
});
0.0.2

10 years ago

0.0.1

10 years ago