• Nov 19, 2022 •CodeCatch
0 likes • 3 views
function Welcome(props) { return <h1>Hello, {props.name}</h1>; } function App() { return ( <div> <Welcome name="Sara" /> <Welcome name="Cahal" /> <Welcome name="Edite" /> </div> ); } ReactDOM.render( <App />, document.getElementById('root') );
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));
• May 17, 2021 •LeifMessinger
0 likes • 2 views
//Upvotes comments according to a regex pattern. I tried it out on https://www.reddit.com/r/VALORANT/comments/ne74n4/please_admire_this_clip_precise_gunplay_btw/ //Known bugs: //If a comment was already upvoted, it gets downvoted //For some reason, it has around a 50-70% success rate. The case insensitive bit works, but I think some of the query selector stuff gets changed. Still, 50% is good let comments = document.getElementsByClassName("_3tw__eCCe7j-epNCKGXUKk"); //Comment class let commentsToUpvote = []; const regexToMatch = /wtf/gi; for(let comment of comments){ let text = comment.querySelector("._1qeIAgB0cPwnLhDF9XSiJM"); //Comment content class if(text == undefined){ continue; } text = text.textContent; if(regexToMatch.test(text)){ console.log(text); commentsToUpvote.push(comment); } } function upvote(comment){ console.log(comment.querySelector(".icon-upvote")); //Just showing you what it's doing comment.querySelector(".icon-upvote").click(); } function slowRecurse(){ let comment = commentsToUpvote.pop(); //It's gonna go bottom to top but whatever if(comment != undefined){ upvote(comment); setTimeout(slowRecurse,500); } } slowRecurse();
0 likes • 0 views
const copyToClipboard = str => { const el = document.createElement('textarea'); el.value = str; el.setAttribute('readonly', ''); el.style.position = 'absolute'; el.style.left = '-9999px'; document.body.appendChild(el); const selected = document.getSelection().rangeCount > 0 ? document.getSelection().getRangeAt(0) : false; el.select(); document.execCommand('copy'); document.body.removeChild(el); if (selected) { document.getSelection().removeAllRanges(); document.getSelection().addRange(selected); } }; copyToClipboard('Lorem ipsum'); // 'Lorem ipsum' copied to clipboard.
• Mar 11, 2021 •C S
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;
• Jan 26, 2023 •AustinLeath
0 likes • 5 views
function printHeap(heap, index, level) { if (index >= heap.length) { return; } console.log(" ".repeat(level) + heap[index]); printHeap(heap, 2 * index + 1, level + 1); printHeap(heap, 2 * index + 2, level + 1); } //You can call this function by passing in the heap array and the index of the root node, which is typically 0, and level = 0. let heap = [3, 8, 7, 15, 17, 30, 35, 2, 4, 5, 9]; printHeap(heap,0,0)