leaves.js 444 B

12345678910111213141516171819202122
  1. var traverse = require('./');
  2. var test = require('testling');
  3. test('leaves', function (t) {
  4. var obj = {
  5. a : [1,2,3],
  6. b : 4,
  7. c : [5,6],
  8. d : { e : [7,8], f : 9 }
  9. };
  10. var acc = [];
  11. traverse(obj).forEach(function (x) {
  12. if (this.isLeaf) acc.push(x);
  13. });
  14. t.deepEqual(
  15. acc, [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ],
  16. 'traversal in the proper order'
  17. );
  18. t.end();
  19. });