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 vintageInsertionSort = (data) => { | |
console.log('data input : ', data); | |
for (let i = 1; i < data.length; i++) { | |
console.log('data i : ', data); | |
// First, choose the element at index 1 | |
let current = data[i]; | |
let j; |
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 vintageLinearSearch = (data, target) => { | |
for (let i in data) { | |
if (data[i] === target) return i | |
} | |
return -1 | |
} | |
console.log(vintageLinearSearch([1, 2, 3, 4], 1)) // 0 | |
console.log(vintageLinearSearch([1, 2, 3, 4], 4)) // 3 | |
console.log(vintageLinearSearch([1, 2, 3, 4], 6)) // -1 |
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 getItems = (data, start, end) => { | |
if (data && | |
data.length > 0 && | |
start >= 0 && | |
end <= data.length && | |
start < end) { | |
return data.slice(start, end); // immutable | |
} | |
return ([]); |
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
class BinarySearchTreeNode { | |
constructor(key, value = key, parent = null) { | |
this.key = key; | |
this.value = value; | |
this.parent = parent; | |
this.left = null; | |
this.right = null; | |
} | |
get isLeaf() { |
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
class BinarySearchTree { | |
constructor(key, value = key) { | |
this.root = new BinarySearchTreeNode(key, value); | |
} | |
*inOrderTraversal(node = this.root) { | |
if (node.left) yield* this.inOrderTraversal(node.left); | |
yield node; | |
if (node.right) yield* this.inOrderTraversal(node.right); | |
} |
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 NodeColor = { | |
RED: 'RED', | |
BLACK: 'BLACK', | |
} | |
class RBTNode { | |
constructor(value, parent = null) { | |
this.value = value | |
this.left = null | |
this.right = null |
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
class RedBlackTree { | |
constructor() { | |
this.root = null | |
} | |
insert(value) { | |
// Define an inner helper function for the recursive insertion | |
const insertHelper = (node) => { | |
// The current node we're considering | |
const currNode = node |
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
class BTreeNode { | |
constructor(isLeaf) { | |
/** | |
* @type {number[]} list of values in the node | |
*/ | |
this.values = []; | |
/** | |
* @type {boolean} is a leaf | |
*/ | |
this.leaf = isLeaf; |
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
class BTree { | |
constructor(order) { | |
/** @type {number} */ | |
this.order = order; | |
/** | |
* Root node of the tree. | |
* @type {BTreeNode} | |
*/ | |
this.root = null; | |
} |
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
<div class="card-container"> | |
<div class="card"> | |
<div class="card-header"> | |
<img | |
src="https://img.freepik.com/premium-photo/retro-video-game-console-gaming-background_670382-215491.jpg?w=400" | |
alt="Game image" | |
/> | |
</div> | |
<div class="card-body"> | |
<strong>World Impact</strong> |