Skip to content

Commit

Permalink
leaf example
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Jul 9, 2010
1 parent fa8265b commit 23ccea5
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions examples/leaves.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env node
var sys = require('sys');
var Traverse = require('traverse').Traverse;

var acc = [];
Traverse({
a : [1,2,3],
b : 4,
c : [5,6],
d : { e : [7,8], f : 9 }
}).forEach(function (x) {
if (this.isLeaf) acc.push(x);
});
sys.puts(acc.join(' '));

/* Output:
1 2 3 4 5 6 7 8 9
*/

0 comments on commit 23ccea5

Please sign in to comment.