• Nov 19, 2022 •CodeCatch
0 likes • 1 view
// There are n rings and each ring is either red, green, or blue. The rings are distributed across ten rods labeled from 0 to 9. // You are given a string rings of length 2n that describes the n rings that are placed onto the rods. Every two characters in rings forms a color-position pair that is used to describe each ring where: // The first character of the ith pair denotes the ith ring's color ('R', 'G', 'B'). // The second character of the ith pair denotes the rod that the ith ring is placed on ('0' to '9'). // For example, "R3G2B1" describes n == 3 rings: a red ring placed onto the rod labeled 3, a green ring placed onto the rod labeled 2, and a blue ring placed onto the rod labeled 1. // Return the number of rods that have all three colors of rings on them. let rings = "B0B6G0R6R0R6G9"; var countPoints = function(rings) { let sum = 0; // Always 10 Rods for (let i = 0; i < 10; i++) { if (rings.includes(`B${i}`) && rings.includes(`G${i}`) && rings.includes(`R${i}`)) { sum+=1; } } return sum; }; console.log(countPoints(rings));
• Jan 25, 2023 •C S
0 likes • 9 views
// Vanilla JS Solution: var app = document.getElementById('app'); var typewriter = new Typewriter(app, { loop: true }); typewriter .typeString("I'm John and I'm a super cool web developer") .pauseFor(3000) .deleteChars(13) // "web developer" = 13 characters .typeString("person to talk with!") // Will display "I'm John and I'm a super cool person to talk with!" .start(); // React Solution: import Typewriter from 'typewriter-effect'; <Typewriter options={{ loop: true }} onInit={typewriter => { typewriter .typeString("I'm John and I'm a super cool web developer") .pauseFor(3000) .deleteChars(13) // "web developer" = 13 characters .typeString("person to talk with!") // Will display "I'm John and I'm a super cool person to talk with!" .start(); }} />
0 likes • 0 views
const primes = num => { let arr = Array.from({ length: num - 1 }).map((x, i) => i + 2), sqroot = Math.floor(Math.sqrt(num)), numsTillSqroot = Array.from({ length: sqroot - 1 }).map((x, i) => i + 2); numsTillSqroot.forEach(x => (arr = arr.filter(y => y % x !== 0 || y === x))); return arr; }; primes(10); // [2, 3, 5, 7]
const head = arr => (arr && arr.length ? arr[0] : undefined); head([1, 2, 3]); // 1 head([]); // undefined head(null); // undefined head(undefined); // undefined
function Clock(props) { return ( <div> <h1>Hello, world!</h1> <h2>It is {props.date.toLocaleTimeString()}.</h2> </div> ); } function tick() { ReactDOM.render( <Clock date={new Date()} />, document.getElementById('root') ); } setInterval(tick, 1000);
• Oct 29, 2020 •LeifMessinger
0 likes • 2 views
questions = Array.from(document.querySelectorAll(".multiple-choice-question")); async function hackRadio(question){ if(question.querySelector(".question-chevron").getAttribute("aria-label") == "Question completed") return; let answerChoices = question.querySelectorAll(".zb-radio-button"); async function guess(answerChoice){ answerChoice.querySelector("label").click(); } let pause = 0; for(let answerChoice of answerChoices){ setTimeout(()=>{guess(answerChoice)},pause); //No need to check given that it will record the correct answer anyways. pause += 1000; } } for(let question of questions){ hackRadio(question); } questions = Array.from(document.querySelectorAll(".short-answer-question")); async function hackShortAnswer(question){ if(question.querySelector(".question-chevron").getAttribute("aria-label") == "Question completed") return; question.querySelector("textarea").value = question.querySelector(".forfeit-answer").textContent; //question.querySelector(".check-button").click(); They are smart bastards } for(let question of questions){ const showAnswerButton = question.querySelector(".show-answer-button"); showAnswerButton.click(); showAnswerButton.click(); hackShortAnswer(question); }