PageNode.js 534 B

12345678910111213141516171819202122232425262728293031
  1. export class PageNode {
  2. page;
  3. children;
  4. constructor() {
  5. this.children = [];
  6. }
  7. /**
  8. * return generations num of decendants
  9. *
  10. * ex:
  11. * /foo -2
  12. * /foo/bar -1
  13. * /foo/bar/buz 0
  14. *
  15. * @returns generations num of decendants
  16. *
  17. * @memberOf PageNode
  18. */
  19. getDecendantsGenerationsNum() {
  20. if (this.children.length == 0) {
  21. return 0;
  22. }
  23. return -1 + Math.max.apply(null, this.children.map((child) => {
  24. return child.getDecendantsGenerationsNum();
  25. }))
  26. }
  27. }