Loading...
More JavaScript Posts
const gcd = (...arr) => {const _gcd = (x, y) => (!y ? x : gcd(y, x % y));return [...arr].reduce((a, b) => _gcd(a, b));};gcd(8, 36); // 4gcd(...[12, 8, 32]); // 4
const permutations = arr => {if (arr.length <= 2) return arr.length === 2 ? [arr, [arr[1], arr[0]]] : arr;return arr.reduce((acc, item, i) =>acc.concat(permutations([...arr.slice(0, i), ...arr.slice(i + 1)]).map(val => [item,...val,])),[]);};permutations([1, 33, 5]);// [ [1, 33, 5], [1, 5, 33], [33, 1, 5], [33, 5, 1], [5, 1, 33], [5, 33, 1] ]
//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);}
function copyString(text){async function navigatorClipboardCopy(text){if(document.location.protocol != "https:"){return false;}return new Promise((resolve, reject)=>{navigator.clipboard.writeText(text).then(()=>{resolve(true);}, ()=>{resolve(false);});});}function domCopy(text){if(!(document.execCommand)){console.warn("They finally deprecated document.execCommand!");}const input = document.createElement('textarea');input.value = text;document.body.appendChild(input);input.select();const success = document.execCommand('copy');document.body.removeChild(input);return success;}function promptCopy(){prompt("Copy failed. Might have ... somewhere. Check console.", text);console.log(text);}function done(){alert("Copied to clipboard");}navigatorClipboardCopy(text).catch(()=>{return false;}).then((success)=>{if(success){done();}else{if(domCopy(text)){done();}else{promptCopy();}}});}
const express = require('express')const app = express()const port = 3000app.get('/', (req, res) => {res.send('Hello World!')})app.listen(port, () => {console.log(`Example app listening on port ${port}`)})
//JavaScript program to swap two variables//take input from the userslet a = prompt('Enter the first variable: ');let b = prompt('Enter the second variable: ');// XOR operatora = a ^ bb = a ^ ba = a ^ bconsole.log(`The value of a after swapping: ${a}`);console.log(`The value of b after swapping: ${b}`);