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
import React, { useState, useEffect } from "react"; | |
export default function OrderDashboardBadWay({ userId }) { | |
const [orders, setOrders] = useState([]); | |
const [loading, setLoading] = useState(true); | |
const [error, setError] = useState(null); | |
const [selectedOrder, setSelectedOrder] = useState(null); | |
const [formattedOrders, setFormattedOrders] = useState([]); | |
useEffect(() => { |
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
function formatUsersBadWay(users) { | |
// Keep only valid users: phone & email not null | |
for (let i = 0; i < users.length; i++) { | |
const user = users[i]; | |
if (user.email === null || user.phone === null) { | |
users.splice(i, 1); | |
} | |
} | |
// Sort by name alphabetically |
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 formatVirementsBadWay = (virements) => { | |
let dataSource = []; | |
for (let i = 0; i < virements.length; i++) { | |
const virement = virements[i]; | |
const uiVirement = {}; | |
// Reference interne | |
uiVirement.referenceInterne = virement.referenceInterne; | |
// Format emetteur |
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 = true) { | |
this.isLeaf = isLeaf; | |
this.keys = []; // Array of keys | |
this.children = []; // Array of child pointers (BTreeNode instances) | |
} | |
} | |
class BTree { | |
constructor(order = 3) { |
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 Node { | |
constructor(value, color = 'RED') { | |
this.value = value; | |
this.color = color; // Nodes start as RED | |
this.left = null; | |
this.right = null; | |
this.parent = null; | |
} | |
isRed() { |
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 Node { | |
constructor(value) { | |
this.value = value; | |
this.left = null; | |
this.right = null; | |
this.height = 1; // Height of the node for balance factor calculations | |
} | |
} | |
class AVLTree { |
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 Node { | |
constructor(value) { | |
this.value = value; | |
this.left = null; | |
this.right = null; | |
} | |
} | |
class BinarySearchTree { | |
constructor() { |
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
import http from 'http'; | |
import url from 'url'; | |
// Validation function to perform security checks | |
const validateRequest = (req) => { | |
const apiKey = req.headers['x-api-key']; | |
if (!apiKey || apiKey !== 'your-secure-api-key') { | |
console.log('Invalid API Key'); | |
return false; | |
} |
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 validator = { | |
set(obj, prop, value, receiver) { | |
if (prop === "age") { | |
if (!Number.isInteger(value)) { | |
throw new TypeError("The age is not an integer"); | |
} | |
if (value > 200) { | |
throw new RangeError("The age seems invalid"); | |
} | |
} |
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
// Function to create a reactive store | |
function createStore(initialState) { | |
// Store the initial state in a private variable | |
let state = initialState; | |
// Array to hold subscribers (callbacks) | |
const subscribers = []; | |
// Create a proxy for the state object | |
const stateProxy = new Proxy(state, { |
NewerOlder