Last active
June 13, 2017 05:50
-
-
Save abiodun0/84bcf2842313a019683c3af71bb6e5aa to your computer and use it in GitHub Desktop.
linkedList and tress functional
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const Nil = {}; | |
| function _LinkedList(h, t) { | |
| this.head = h; | |
| this.tail = t; | |
| } | |
| const LinkedList = (h, t) => new _LinkedList(h, t); | |
| const newLinkedList = LinkedList(5, LinkedList(7, LinkedList(10, Nil))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const Empty = {}; | |
| function _Leaf(x) { this.x = x} | |
| const Leaf = (x) => new _Leaf(x) | |
| function _Node(l, x, r) { | |
| this.left = l; | |
| this.x = x; | |
| this.right = r; | |
| } | |
| const Node = (l,x,r) => new _Node(l,x,r) | |
| const newTree = Node(Node(Leaf(3), 1, Leaf(2)), 1, Node(Leaf(4), 1, Leaf(7))) | |
| console.log(newTree, 'trees') | |
| const newTree2 = Node(Node(Node(Leaf(4)), 2), 1, Node(Node(Leaf(4)), 3, Node(undefined, 6, Leaf(7)))) | |
| console.log(JSON.stringify(newTree2, null, 4), 'second Tree'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment