image.png

  1. class Node {
  2. constructor(data) {
  3. this.data = data;
  4. this.left = null;
  5. this.right = null;
  6. }
  7. insert(data) {
  8. if (data < this.data && this.left) {
  9. this.left.insert(data);
  10. } else if (data < this.data) {
  11. this.left = new Node(data);
  12. } else if (data > this.data && this.right) {
  13. this.right.insert(data);
  14. } else if (data > this.data) {
  15. this.right = new Node(data);
  16. }
  17. }
  18. }
  19. // to be valid, node should satisfy min and max ALONGSIDE with all his children
  20. // first we check if node data satisfying min and max
  21. // then we do recursive check for node left and right children
  22. function validate(node, min = null, max = null) {
  23. const { left, right, data } = node;
  24. // node is invalid when doesn't satisfy min or max
  25. if ((max && data > max) || (min && data < min)) return false;
  26. // true by default, since if node doesn't have a child, it should be accepted as valid
  27. let isLeftChildValid = true;
  28. let isRightChildValid = true;
  29. if (left) isLeftChildValid = validate(left, min, data);
  30. if (right) isRightChildValid = validate(right, data, max);
  31. // at this step node validity depends on validity of his children
  32. // because all check of node data itself was made above (line 8)
  33. return isLeftChildValid && isRightChildValid;
  34. }

image.png
image.png


  1. // --- Directions
  2. // Create an 'eventing' library out of the
  3. // Events class. The Events class should
  4. // have methods 'on', 'trigger', and 'off'.
  5. class Events {
  6. constructor() {
  7. this.event = {}
  8. }
  9. // Register an event handler
  10. on(eventName, callback) {
  11. if (this.event.hasOwnProperty(eventName)) {
  12. this.event[eventName].push(callback);
  13. } else {
  14. this.event[eventName] = [callback];
  15. }
  16. }
  17. // Trigger all callbacks associated
  18. // with a given eventName
  19. trigger(eventName) {
  20. if (!this.event.hasOwnProperty(eventName)) return;
  21. for (let cb of this.event[eventName]) {
  22. cb();
  23. }
  24. }
  25. // Remove all event handlers associated
  26. // with the given eventName
  27. off(eventName) {
  28. delete this.event[eventName];
  29. }
  30. }

CSS Transition

image.png

image.png

image.png


CSS Animation


image.png

image.pngimage.png

image.png

image.png