• Feb 6, 2021 •LeifMessinger
0 likes • 2 views
class SequentialQueue{ //if you want it to go backwards, too bad next(){ return this.i++; } constructor(start = 0){ this.i = start; } } const que = new SequentialQueue(0); for(let i = 0; i < 10; i++){ console.log(que.next()); }
• Apr 14, 2023 •Helper
0 likes • 8 views
const quickSort = arr => { const a = [...arr]; if (a.length < 2) return a; const pivotIndex = Math.floor(arr.length / 2); const pivot = a[pivotIndex]; const [lo, hi] = a.reduce( (acc, val, i) => { if (val < pivot || (val === pivot && i != pivotIndex)) { acc[0].push(val); } else if (val > pivot) { acc[1].push(val); } return acc; }, [[], []] ); return [...quickSort(lo), pivot, ...quickSort(hi)]; }; console.log(quickSort([1, 6, 1, 5, 3, 2, 1, 4])) // [1, 1, 1, 2, 3, 4, 5, 6]
• Apr 26, 2025 •hasnaoui1
console.log("xa")
• Mar 11, 2021 •C S
0 likes • 6 views
router.post("/", async (req, res) => { const { email, password } = req.body; try { if (!email) return res.status(400).json({ msg: "An email is required" }); if (!password) return res.status(400).json({ msg: "A password is required" }); const user = await User.findOne({ email }).select("_id password"); if (!user) return res.status(400).json({ msg: "Invalid credentials" }); const match = await bcrypt.compare(password, user.password); if (!match) return res.status(400).json({ msg: "Invalid credentials" }); const accessToken = genAccessToken({ id: user._id }); const refreshToken = genRefreshToken({ id: user._id }); res.cookie("token", refreshToken, { expires: new Date(Date.now() + 604800), httpOnly: true, }); res.json({ accessToken }); } catch (err) { console.log(err.message); res.status(500).json({ msg: "Error logging in user" }); } });
• Aug 30, 2024 •C S
1 like • 18 views
# Acronyms ## Computer Numerical Control (CNC) - Typicalldfdfsdffdafdasgfdgfgfdfdafdasfdafda
• Nov 19, 2022 •CodeCatch
const luhnCheck = num => { let arr = (num + '') .split('') .reverse() .map(x => parseInt(x)); let lastDigit = arr.splice(0, 1)[0]; let sum = arr.reduce( (acc, val, i) => (i % 2 !== 0 ? acc + val : acc + ((val *= 2) > 9 ? val - 9 : val)), 0 ); sum += lastDigit; return sum % 10 === 0; }; luhnCheck('4485275742308327'); // true luhnCheck(6011329933655299); // true luhnCheck(123456789); // false