Node.js的Hashish模块

hashish包含了很多数据结构操作功能。

var Hash = require('hashish');

Hash({ a : 1, b : 2, c : 3, d : 4 })
.map(function (x) { return x * 10 })
.filter(function (x) { return x < 30 })
.forEach(function (x, key) {
console.log(key + ' => ' + x);
})
;

 流程:

Hash构造是{ a : 1, b : 2, c : 3, d : 4 };>>Hash值乘以10,hash结构{ a : 10, b : 20, c : 30, d : 40 }>>去掉小于30的>>forEach遍历输出。

得到

 
a => 10
b => 20

 hashish可以以链接的形式加到hash上

 
var Hash = require('hashish');
var obj = { a : 1, b : 2, c : 3, d : 4 };

var mapped = Hash.map(obj, function (x) {
return x * 10
});

console.dir(mapped);

 hash输出的值乘以10

{ a: 10, b: 20, c: 30, d: 40 }

猜你喜欢

转载自873719187.iteye.com/blog/2269926