• Mar 11, 2021 •C S
0 likes • 0 views
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;
• Nov 19, 2022 •CodeCatch
0 likes • 3 views
const linearSearch = (arr, item) => { for (const i in arr) { if (arr[i] === item) return +i; } return -1; }; linearSearch([2, 9, 9], 9); // 1 linearSearch([2, 9, 9], 7); // -1
• Oct 15, 2022 •CodeCatch
3 likes • 4 views
const MongoClient = require('mongodb').MongoClient; const assert = require('assert'); // Connection URL const url = 'mongodb://localhost:27017'; // Database Name const dbName = 'myproject'; // Use connect method to connect to the server MongoClient.connect(url, function(err, client) { assert.equal(null, err); console.log("Connected successfully to server"); const db = client.db(dbName); client.close(); });
• Nov 18, 2022 •AustinLeath
// Get the text that the user has selected const getSelectedText = () => window.getSelection().toString(); getSelectedText();
• Sep 13, 2023 •C S
0 likes • 2 views
/** * @param {number[]} nums * @return {boolean} */ var containsDuplicate = function(nums) { return new Set(nums).size !== nums.length };
• Mar 22, 2022 •LeifMessinger
0 likes • 1 view
//QM Helper by Leif Messinger //Groups numbers by number of bits and shows their binary representations. //To be used on x.com const minterms = prompt("Enter your minterms separated by commas").split(",").map(x => parseInt(x.trim())); const maxNumBits = minterms.reduce(function(a, b) { return Math.max(a, Math.log2(b)); }); const bitGroups = []; for(let i = 0; i < maxNumBits; ++i){ bitGroups.push([]); } for(const minterm of minterms){ let outputString = (minterm+" "); //Count the bits let count = 0; for (var i = maxNumBits; i >= 0; --i) { if((minterm >> i) & 1){ ++count; outputString += "1"; }else{ outputString += "0"; } } bitGroups[count].push(outputString); } document.body.textContent = ""; document.body.style.setProperty("white-space", "pre"); for(const group of bitGroups){ for(const outputString of group){ document.body.textContent += outputString + "\r\n"; } }