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 })
.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
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);
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 }
本文介绍了一个名为hashish的库,该库支持多种数据结构操作,包括映射、过滤及遍历等。通过实例展示了如何使用此库进行数据转换与处理。
1781

被折叠的 条评论
为什么被折叠?



