* Main function to run the example
()
| 11 | * Main function to run the example |
| 12 | */ |
| 13 | async function main() { |
| 14 | console.log("===== E2B JavaScript Code Execution Example ====="); |
| 15 | |
| 16 | // Simple JavaScript code example |
| 17 | const jsCode = ` |
| 18 | // Define a class for a simple data structure |
| 19 | class BinarySearchTree { |
| 20 | constructor() { |
| 21 | this.root = null; |
| 22 | } |
| 23 | |
| 24 | // Node class for the tree |
| 25 | static Node = class { |
| 26 | constructor(value) { |
| 27 | this.value = value; |
| 28 | this.left = null; |
| 29 | this.right = null; |
| 30 | } |
| 31 | }; |
| 32 | |
| 33 | // Insert a value into the tree |
| 34 | insert(value) { |
| 35 | const newNode = new BinarySearchTree.Node(value); |
| 36 | |
| 37 | if (this.root === null) { |
| 38 | this.root = newNode; |
| 39 | return; |
| 40 | } |
| 41 | |
| 42 | const insertNode = (node, newNode) => { |
| 43 | if (newNode.value < node.value) { |
| 44 | if (node.left === null) { |
| 45 | node.left = newNode; |
| 46 | } else { |
| 47 | insertNode(node.left, newNode); |
| 48 | } |
| 49 | } else { |
| 50 | if (node.right === null) { |
| 51 | node.right = newNode; |
| 52 | } else { |
| 53 | insertNode(node.right, newNode); |
| 54 | } |
| 55 | } |
| 56 | }; |
| 57 | |
| 58 | insertNode(this.root, newNode); |
| 59 | } |
| 60 | |
| 61 | // In-order traversal |
| 62 | inOrderTraversal(callback) { |
| 63 | const traverse = (node, callback) => { |
| 64 | if (node !== null) { |
| 65 | traverse(node.left, callback); |
| 66 | callback(node.value); |
| 67 | traverse(node.right, callback); |
| 68 | } |
| 69 | }; |
| 70 |
no test coverage detected