您的位置:首页 > Web前端 > Node.js

Node.js的Hashish模块

2016-01-11 21:17 651 查看

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 }

 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: