• Nov 19, 2022 •CodeCatch
0 likes • 0 views
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);
0 likes • 1 view
const getURLParameters = url => (url.match(/([^?=&]+)(=([^&]*))/g) || []).reduce( (a, v) => ( (a[v.slice(0, v.indexOf('='))] = v.slice(v.indexOf('=') + 1)), a ), {} );
// 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 26, 2023 •AustinLeath
0 likes • 6 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)
• Mar 10, 2022 •LeifMessinger
//Use at https://mee6.xyz/leaderboard/732262089447702588 //Higher the spammy stat, the more spammy that person is. //This is because mee doesn't give experience to people who post more comments in a minute. function statBlock(title, value){ let elm = document.createElement("div"); elm.className = "leaderboardPlayerStatBlock"; let titleElm = document.createElement("div"); titleElm.className = "leaderboardPlayerStatName"; titleElm.textContent = title; let valueElm = document.createElement("div"); valueElm.className = "leaderboardPlayerStatValue"; valueElm.textContent = value; elm.appendChild(titleElm); elm.appendChild(valueElm); elm.remove = function(){ this.parentElement.removeChild(this); } return elm; } for(let player of Array.from(document.getElementsByClassName("leaderboardPlayer"))){ if(player.spamminess) player.spamminess.remove(); let messages = null; let experience = null; const statBlockArray = Array.from(player.querySelectorAll(".leaderboardPlayerStatBlock")); for(let statBlock of statBlockArray){ const statName = statBlock.querySelector(".leaderboardPlayerStatName").textContent; const text = statBlock.querySelector(".leaderboardPlayerStatValue").textContent; const number = ((text.includes("k"))? (text.replace("k","") * 1000.0) : +(text)); if(statName.includes("MESSAGES")){ messages = number; }else if(statName.includes("EXPERIENCE")){ experience = number; } } const stats = player.querySelector(".leaderboardPlayerStats"); const messagesElement = stats.firstChild; const spamminess = ((messages/experience)*2000.0).toFixed(2); player.spamminess = stats.insertBefore(statBlock("SPAMMINESS", spamminess), messagesElement); }
• Oct 15, 2022 •CodeCatch
2 likes • 9 views
var invertTree = function(root) { const reverseNode = node => { if (node == null) { return null } reverseNode(node.left); reverseNode(node.right); let holdLeft = node.left; node.left = node.right; node.right = holdLeft; return node; } return reverseNode(root); };