Skip to content

Instantly share code, notes, and snippets.

View jordanrios94's full-sized avatar
😎
looking at a screen

Jordan Rios jordanrios94

😎
looking at a screen
  • 101Ways
  • London
View GitHub Profile

http:// is not allowed

Please follow instructions below on how to setup https://

Start a development server with https proxy

Install mkcert for creating a valid certificate (Mac OS):

$ brew install mkcert
@jordanrios94
jordanrios94 / sorting.js
Last active February 9, 2023 09:54
Sorting Algorithms
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) {
@jordanrios94
jordanrios94 / tree.js
Last active February 3, 2023 13:28
Tree
/*
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.
*/
@jordanrios94
jordanrios94 / fromLast.js
Created February 3, 2023 10:22
LinkedList From Last
/*
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);
@jordanrios94
jordanrios94 / circular.js
Created February 3, 2023 10:14
LinkedList Circular
/*
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) {
@jordanrios94
jordanrios94 / midpoint.js
Created February 3, 2023 09:57
LinkedList Midpoint
/*
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();
@jordanrios94
jordanrios94 / Tree.js
Last active February 3, 2023 02:14
Generators
class Tree {
constructor(value = null, children = []) {
this.value = value;
this.children = children;
}
*printValues() {
yield this.value;
for (let child of this.children) {
@jordanrios94
jordanrios94 / LinkedList.js
Last active February 3, 2023 02:33
Linked Lists
class LinkedList {
constructor() {
this.head = null;
}
insertFirst(data) {
this.head = new Node(data, this.head);
}
size() {