• Nov 19, 2022 •CodeCatch
0 likes • 1 view
let nums = [1,2,3,1] var containsDuplicate = function(nums) { let obj = {}; for(let i =0; i< nums.length; i++){ if(obj[nums[i]]){ obj[nums[i]] += 1; return true; }else{ obj[nums[i]] = 1; } } return false; }; console.log(containsDuplicate(nums));
0 likes • 0 views
const head = arr => (arr && arr.length ? arr[0] : undefined); head([1, 2, 3]); // 1 head([]); // undefined head(null); // undefined head(undefined); // undefined
• Nov 18, 2022 •AustinLeath
0 likes • 2 views
import Head from 'next/head' import Image from 'next/image' import styles from '../styles/Home.module.css' const { exec } = require("child_process"); exec("sensors|grep "high"|grep "Core"|cut -d "+" -f2|cut -d "." -f1|sort -nr|sed -n 1p", (error, stdout, stderr) => { if (error) { console.log(`error: ${error.message}`); return; } if (stderr) { console.log(`stderr: ${stderr}`); return; } console.log(`stdout: ${stdout}`); }); export default function Home() { return ( <div className={styles.container}> <Head> <title>Create Next App</title> <meta name="description" content="Generated by create next app" /> <link rel="icon" href="/favicon.ico" /> </Head> <main className={styles.main}> <h1 className={styles.title}> Welcome to <a href="https://nextjs.org">Next.js!</a> </h1> <p className={styles.description}> Get started by editing{' '} <code className={styles.code}>pages/index.js</code> </p> <div className={styles.grid}> <a href="https://nextjs.org/docs" className={styles.card}> <h2>Documentation →</h2> <p>Find in-depth information about Next.js features and API.</p> </a> <a href="https://nextjs.org/learn" className={styles.card}> <h2>Learn →</h2> <p>Learn about Next.js in an interactive course with quizzes!</p> </a> <a href="https://github.com/vercel/next.js/tree/canary/examples" className={styles.card} > <h2>Examples →</h2> <p>Discover and deploy boilerplate example Next.js projects.</p> </a> <a href="https://vercel.com/new?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app" className={styles.card} > <h2>Deploy →</h2> <p> Instantly deploy your Next.js site to a public URL with Vercel. </p> </a> </div> </main> <footer className={styles.footer}> <a href="https://vercel.com?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app" target="_blank" rel="noopener noreferrer" > Powered by{' '} <span className={styles.logo}> <Image src="/vercel.svg" alt="Vercel Logo" width={72} height={16} /> </span> </a> </footer> </div> ) }
• Mar 11, 2021 •C S
0 likes • 4 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" }); } });
const getURLParameters = url => (url.match(/([^?=&]+)(=([^&]*))/g) || []).reduce( (a, v) => ( (a[v.slice(0, v.indexOf('='))] = v.slice(v.indexOf('=') + 1)), a ), {} );
const insertionSort = arr => arr.reduce((acc, x) => { if (!acc.length) return [x]; acc.some((y, j) => { if (x <= y) { acc.splice(j, 0, x); return true; } if (x > y && j === acc.length - 1) { acc.splice(j + 1, 0, x); return true; } return false; }); return acc; }, []); insertionSort([6, 3, 4, 1]); // [1, 3, 4, 6]