Loading...
More JavaScript Posts
require("dotenv").config();const mongoose = require("mongoose");const db = process.env.MONGO_URI;const connectDB = async () => {try {await mongoose.connect(db, {useNewUrlParser: true,useUnifiedTopology: true,useFindAndModify: false,useCreateIndex: true});console.log("MongoDB Connected");} catch (err) {console.error(err.message);}};module.exports = connectDB;
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 arithmeticProgression = (n, lim) =>Array.from({ length: Math.ceil(lim / n) }, (_, i) => (i + 1) * n );arithmeticProgression(5, 25); // [5, 10, 15, 20, 25]
/*** @param {number[]} nums* @return {boolean}*/var containsDuplicate = function(nums) {return new Set(nums).size !== nums.length};
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
const deepMerge = (a, b, fn) =>[...new Set([...Object.keys(a), ...Object.keys(b)])].reduce((acc, key) => ({ ...acc, [key]: fn(key, a[key], b[key]) }),{});deepMerge({ a: true, b: { c: [1, 2, 3] } },{ a: false, b: { d: [1, 2, 3] } },(key, a, b) => (key === 'a' ? a && b : Object.assign({}, a, b)));// { a: false, b: { c: [ 1, 2, 3 ], d: [ 1, 2, 3 ] } }