Guest User

Untitled

a guest
Oct 18th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. const tree = {
  2. value: 6,
  3. left: {
  4. value: 4,
  5. left: {
  6. value: 1,
  7. left: null,
  8. right: null
  9. },
  10. right: {
  11. value: 5,
  12. left: null,
  13. right: null
  14. }
  15. },
  16. right: {
  17. value: 8,
  18. left: null,
  19. right: {
  20. value: 9,
  21. left: null,
  22. right: null
  23. }
  24. }
  25. }
  26.  
  27. const check = tree => {
  28. const current = tree
  29. const expression = current.value > current.left.value && current.value < current.right.value
  30.  
  31. if (!current.left) return true
  32. if (!expressiion) return false
  33.  
  34. return check(current.left)
  35. }
  36.  
  37. console.log(check(tree))
Add Comment
Please, Sign In to add comment