Skip to content

Instantly share code, notes, and snippets.

View helabenkhalfallah's full-sized avatar
🎯
Focusing

Héla Ben Khalfallah helabenkhalfallah

🎯
Focusing
View GitHub Profile
@helabenkhalfallah
helabenkhalfallah / vintage-insertion-sort.js
Last active July 10, 2022 16:05
Vintage Insertion Sort
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;
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
@helabenkhalfallah
helabenkhalfallah / devoxx-1.js
Created April 12, 2023 16:05
Algorithme Simple
const getItems = (data, start, end) => {
if (data &&
data.length > 0 &&
start >= 0 &&
end <= data.length &&
start < end) {
return data.slice(start, end); // immutable
}
return ([]);
@helabenkhalfallah
helabenkhalfallah / BinarySearchTreeNode.js
Last active February 10, 2024 21:19
BinarySearchTreeNode
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() {
@helabenkhalfallah
helabenkhalfallah / BinarySearchTree.js
Created February 10, 2024 21:14
BinarySearchTree
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);
}
const NodeColor = {
RED: 'RED',
BLACK: 'BLACK',
}
class RBTNode {
constructor(value, parent = null) {
this.value = value
this.left = null
this.right = null
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
@helabenkhalfallah
helabenkhalfallah / BTreeNode.js
Last active February 11, 2024 20:21
BTreeNode
class BTreeNode {
constructor(isLeaf) {
/**
* @type {number[]} list of values in the node
*/
this.values = [];
/**
* @type {boolean} is a leaf
*/
this.leaf = isLeaf;
@helabenkhalfallah
helabenkhalfallah / BTree.js
Last active February 11, 2024 20:23
BTree
class BTree {
constructor(order) {
/** @type {number} */
this.order = order;
/**
* Root node of the tree.
* @type {BTreeNode}
*/
this.root = null;
}
<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>