diff --git a/examples/leaves.js b/examples/leaves.js new file mode 100755 index 0000000..d38709b --- /dev/null +++ b/examples/leaves.js @@ -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 +*/