Skip to content

Instantly share code, notes, and snippets.

View sebastianfdez's full-sized avatar
🏠
Working from home

SF sebastianfdez

🏠
Working from home
View GitHub Profile
@sebastianfdez
sebastianfdez / merge-sort.js
Created September 10, 2020 19:05
Merge Sort in JavaScript
/**
* Quicksort implemented in JS by @sebastianfdez
* @param {number[]} nums
* @returns {number[]}
*/
export function mergeSort(nums) {
if (nums.length <= 1) {
return nums;
}
@sebastianfdez
sebastianfdez / BTree.js
Created April 29, 2020 14:58
BTree with remove function
/**
* btree namespace.
* @type {BTree}
*/
export default class BTree {
constructor(order) {
/** @type {number} */
this.order = order;
/**
* Root node of the tree.
@sebastianfdez
sebastianfdez / BTree.js
Last active May 18, 2024 06:33
FINAL COMPLETE BTREE CLASS
export class BTreeNode {
constructor(isLeaf) {
/**
* @type {number[]} list of values in the node
*/
this.values = [];
/**
* @type {boolean} is a leaf
*/
this.leaf = isLeaf;
@sebastianfdez
sebastianfdez / BTree.js
Last active April 27, 2020 17:09
TransferValue and MergeNodes function
/**
* btree namespace.
* @type {BTree}
*/
export default class BTree {
...
/**
* Transfer one value from the origin to the target.
* @param {BTreeNode} origin
* @param {BTreeNode} target
@sebastianfdez
sebastianfdez / BTreeNode.js
Last active April 27, 2020 16:48
BTreeNode with get immediate brother function
export class BTreeNode {
...
/**
* Get the immediate with more values. If there no one with extra
* values, return one of the immediate brothers
* @returns {BTreeNode}
*/
getImmediateBrother() {
// Get position of node in parent children list
const index = this.parent.children.indexOf(this);
@sebastianfdez
sebastianfdez / BTree.js
Last active April 28, 2020 08:51
BTree with insertion
/**
* btree namespace.
* @type {BTree}
*/
export default class BTree {
constructor(order) {
/** @type {number} */
this.order = order;
/**
* Root node of the tree.
@sebastianfdez
sebastianfdez / BTree.js
Last active April 28, 2020 08:52
Basic class of a BTree
/**
* btree namespace.
* @type {BTree}
*/
export default class BTree {
constructor(order) {
/** @type {number} */
this.order = order;
/**
* Root node of the tree.
@sebastianfdez
sebastianfdez / BTreeNode.js
Last active April 27, 2020 08:57
Basic BTree in JavaScript
/**
* Basic Node of BTree.
* Keep reference to their children and values.
* Keep a reference to the parent and tree.
*/
export class BTreeNode {
constructor(isLeaf) {
/**
* @type {number[]} list of values in the node
*/