Skip to content

Commit

Permalink
oh right and this example file
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Aug 27, 2010
1 parent 86d71a9 commit d98c125
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions examples/hash.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
var Hash = require('traverse/hash');
var sys = require('sys');

var obj = Hash({ a : 1, b : 2 })
.map(function (v) { return v + 1 })
.update({ b : 30, c : 42 })
.filter(function (v) { return v % 2 == 0 })
.tap(function () {
var anyC = this.some(function (value, key) { return key == 'c' });
// or just this.keys.some, but anyways
console.log(anyC
? "There's a C key this far."
: "There's no C key this far."
);
})
.items
;

/* Output:
There's a C key this far.
{ a : 2, b : 30, c : 42 }
*/
console.log(sys.inspect(obj));

0 comments on commit d98c125

Please sign in to comment.