Loading...
More JavaScript Posts
const binomialCoefficient = (n, k) => {if (Number.isNaN(n) || Number.isNaN(k)) return NaN;if (k < 0 || k > n) return 0;if (k === 0 || k === n) return 1;if (k === 1 || k === n - 1) return n;if (n - k < k) k = n - k;let res = n;for (let j = 2; j <= k; j++) res *= (n - j + 1) / j;return Math.round(res);};binomialCoefficient(8, 2); // 28
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" });}});
import { configureStore } from "@reduxjs/toolkit";import { combineReducers } from "redux";import profile from "./profile";import auth from "./auth";import alert from "./alert";const reducer = combineReducers({profile,auth,alert,});const store = configureStore({ reducer });export default store;
const ResponsiveCardImg = styled(Card.Img)`// For screens wider than 768px@media(min-width: 768px) {// Your responsive styles here.}// For screens smaller than 768px@media(max-width: 768px) {// Your responsive styles here.}`export default function App() {return (<MainContainer><Container><Card text='white' bg='dark' style={styles.mainCard}><ResponsiveCardImgstyle={styles.cardImage}onClick={handleClick}src={apeImage}alt='Degenerate Ape Academy'/><Card.Body><Card.Title className='text-center' as='h2'>{apeId}</Card.Title></Card.Body></Card></Container></MainContainer>);}
const arithmeticProgression = (n, lim) =>Array.from({ length: Math.ceil(lim / n) }, (_, i) => (i + 1) * n );arithmeticProgression(5, 25); // [5, 10, 15, 20, 25]
const celsiusToFahrenheit = (celsius) => celsius * 9/5 + 32;const fahrenheitToCelsius = (fahrenheit) => (fahrenheit - 32) * 5/9;// ExamplescelsiusToFahrenheit(15); // 59celsiusToFahrenheit(0); // 32celsiusToFahrenheit(-20); // -4fahrenheitToCelsius(59); // 15fahrenheitToCelsius(32); // 0