Start a development server with https proxy
Install mkcert for creating a valid certificate (Mac OS):
$ brew install mkcert
function bubbleSort(arr) { | |
for (let i = 0; i < arr.length; i++) { | |
for (let j = 0; j < (arr.length - i - 1); j++) { | |
if (arr[j] > arr[j+1]) { | |
const lesser = arr[j+1]; | |
arr[j+1] = arr[j]; | |
arr[j] = lesser; | |
} | |
} | |
} |
/* | |
Given a node of a binary search tree, validate the binary search tree. | |
- Ensure that every node's left hand child is less than the parent node's value | |
- Ensure that every node's right hand child is greater than the parent | |
*/ | |
function validate(node, min = null, max = null) { | |
if (max !== null && node.data > max) { | |
return false; | |
} |
/* | |
- Implement the Node class to create a binary search tree. The constructor should initialize values 'data', 'left', and 'right'. | |
- Implement the 'insert' method for the Node class. Insert should accept an argument 'data', then create an insert a new node at the appropriate location in the tree. | |
- Implement the 'contains' method for the Node class. Contains should accept a 'data' argument and return the Node in the tree with the same value. | |
*/ | |
class Node { | |
constructor(data) { |
/* | |
1) Create a node class. | |
- The constructor should accept an argument that gets assigned to the data property and initialise an empty arroy for storing children. | |
- The node class should have methods 'add' and 'remove'. | |
2) Create a tree class. The tree constructor should initialise a 'root' property to null. | |
3) Implement 'taverseBFS' and 'traverseDFS' on the tree class. | |
*/ |
/* | |
Given a linked list and integer n, return the element n spaces from the last node in the list. | |
- Do not call the 'size' method of the linked list | |
- Assume that n will always be less than the length of the list. | |
*/ | |
function fromLast(list, n) { | |
let slow = list.getFirst(); | |
let fast = list.getAt(n); | |
/* | |
Given a linked list, return true if the list is circular, false if it is not. | |
*/ | |
function circular(list) { | |
let slow = list.getFirst(); | |
let fast = list.getFirst(); | |
for (let item of list) { | |
if (slow.next && fast.next) { |
/* | |
Return the 'middle' node of a linked list. | |
- If the list has an even number of elements return the node at the end of the first half of the list. | |
- Do not use a counter variable | |
- Do not retrieve the size of the list | |
- Only iterate through the list one time | |
*/ | |
function midpoint(list) { | |
let slow = list.getFirst(); |
class Tree { | |
constructor(value = null, children = []) { | |
this.value = value; | |
this.children = children; | |
} | |
*printValues() { | |
yield this.value; | |
for (let child of this.children) { |
class LinkedList { | |
constructor() { | |
this.head = null; | |
} | |
insertFirst(data) { | |
this.head = new Node(data, this.head); | |
} | |
size() { |