Loading...
More JavaScript Posts
//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);}
const formatDuration = ms => {if (ms < 0) ms = -ms;const time = {day: Math.floor(ms / 86400000),hour: Math.floor(ms / 3600000) % 24,minute: Math.floor(ms / 60000) % 60,second: Math.floor(ms / 1000) % 60,millisecond: Math.floor(ms) % 1000};return Object.entries(time).filter(val => val[1] !== 0).map(([key, val]) => `${val} ${key}${val !== 1 ? 's' : ''}`).join(', ');};formatDuration(1001); // '1 second, 1 millisecond'formatDuration(34325055574); // '397 days, 6 hours, 44 minutes, 15 seconds, 574 milliseconds'
/*** @param {number[]} nums* @param {number} target* @return {number[]}*/var twoSum = function(nums, target) {for(let i = 0; i < nums.length; i++) {for(let j = 0; j < nums.length; j++) {if(nums[i] + nums[j] === target && i !== j) {return [i, j]}}}};
const shuffle = ([...arr]) => {let m = arr.length;while (m) {const i = Math.floor(Math.random() * m--);[arr[m], arr[i]] = [arr[i], arr[m]];}return arr;};const foo = [1, 2, 3];shuffle(foo); // [2, 3, 1], foo = [1, 2, 3]
const quickSort = arr => {const a = [...arr];if (a.length < 2) return a;const pivotIndex = Math.floor(arr.length / 2);const pivot = a[pivotIndex];const [lo, hi] = a.reduce((acc, val, i) => {if (val < pivot || (val === pivot && i != pivotIndex)) {acc[0].push(val);} else if (val > pivot) {acc[1].push(val);}return acc;},[[], []]);return [...quickSort(lo), pivot, ...quickSort(hi)];};console.log(quickSort([1, 6, 1, 5, 3, 2, 1, 4])) // [1, 1, 1, 2, 3, 4, 5, 6]
/*** @param {number[]} nums* @return {number[]}*/var productExceptSelf = function(nums) {var output = [];var leftMult = 1;var rightMult = 1;for (var i=nums.length - 1; i >= 0; i--) {output[i] = rightMult;rightMult *= nums[i];console.log({output: JSON.stringify(output), i})}for (var j=0; j < nums.length; j++) {output[j] *= leftMult;leftMult *= nums[j];console.log({output: JSON.stringify(output), j})}return output;};console.log(productExceptSelf([1, 2, 3, 4]))