• Nov 18, 2022 •AustinLeath
0 likes • 2 views
var d = new Date(); var d = new Date(milliseconds); var d = new Date(dateString); var d = new Date(year, month, day, hours, minutes, seconds, milliseconds);
• Nov 19, 2022 •CodeCatch
0 likes • 1 view
//JavaScript program to swap two variables //take input from the users let a = prompt('Enter the first variable: '); let b = prompt('Enter the second variable: '); // XOR operator a = a ^ b b = a ^ b a = a ^ b console.log(`The value of a after swapping: ${a}`); console.log(`The value of b after swapping: ${b}`);
• Oct 15, 2022 •CodeCatch
2 likes • 8 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); };
0 likes • 0 views
const binomialCoefficient = (n, k) => { if (Number.isNaN(n) || Number.isNaN(k)) return NaN; if (k < 0 || k > n) return 0; if (k === 0 || k === n) return 1; if (k === 1 || k === n - 1) return n; if (n - k < k) k = n - k; let res = n; for (let j = 2; j <= k; j++) res *= (n - j + 1) / j; return Math.round(res); }; binomialCoefficient(8, 2); // 28
// Or const randomColor = () => `#${(~~(Math.random()*(1<<24))).toString(16)}`; console.log(randomColor);
• Nov 8, 2023 •LeifMessinger
0 likes • 6 views
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(); } } }); }