• Nov 19, 2022 •CodeCatch
0 likes • 2 views
const powerset = arr => arr.reduce((a, v) => a.concat(a.map(r => r.concat(v))), [[]]); powerset([1, 2]); // [[], [1], [2], [1, 2]]
• Apr 26, 2025 •hasnaoui1
0 likes • 1 view
console.log("xa")
• Oct 9, 2023 •Helper
0 likes • 278 views
import React, { useState, useEffect } from 'react'; import Link from 'next/link'; export default function CookieBanner() { // Initialize with a default value (false if not previously set in localStorage) const [cookieConsent, setCookieConsent] = useState(() => localStorage.getItem('cookieConsent') === 'true' ? true : false ); useEffect(() => { const newCookieConsent = cookieConsent ? 'granted' : 'denied'; window.gtag('consent', 'update', { analytics_storage: newCookieConsent }); localStorage.setItem('cookieConsent', String(cookieConsent)); }, [cookieConsent]); return !cookieConsent && ( <div> <div> <p> We use cookies to enhance the user experience.{' '} <Link href='/privacy/'>View privacy policy</Link> </p> </div> <div> <button type="button" onClick={() => setCookieConsent(false)}>Decline</button> <button type="button" onClick={() => setCookieConsent(true)}>Allow</button> </div> </div> ) }
//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}`);
0 likes • 0 views
const nums = [1, 2, 3]; const strs = Array.from('est'); nums.push(6); nums.push(4, 9); strs.unshift('t'); nums.length; // 6 nums[nums.length - 1]; // 9 strs[0]; // 't' strs[2]; // 's' nums.slice(1, 3); // [2, 3] nums.map(n => n * 2); // [2, 4, 6, 12, 8, 18] nums.filter(n => n % 2 === 0); // [2, 6, 4] nums.reduce((a, n) => a + n, 0); // 25 strs.reverse(); // ['t', 's', 'e', 't'] strs.join(''); // 'test' const nums = new Set([1, 2, 3]); nums.add(4); nums.add(1); nums.add(5); nums.add(4); nums.size; // 5 nums.has(4); // true nums.delete(4); nums.has(4); // false [...nums]; // [1, 2, 3, 5] nums.clear(); nums.size; // 0 const items = new Map([ [1, { name: 'John' }], [2, { name: 'Mary' }] ]); items.set(4, { name: 'Alan' }); items.set(2, { name: 'Jeff' }); items.size; // 3 items.has(4); // true items.get(2); // { name: 'Jeff' } items.delete(2); items.size; // 2 [...items.keys()]; // [1, 4] [...items.values()]; // [{ name: 'John' }, { name: 'Alan' }] items.clear(); items.size; // 0
• Nov 18, 2022 •AustinLeath
// Or const randomColor = () => `#${(~~(Math.random()*(1<<24))).toString(16)}`; console.log(randomColor);