Loading...
More JavaScript Posts
const powerset = arr =>arr.reduce((a, v) => a.concat(a.map(r => r.concat(v))), [[]]);powerset([1, 2]); // [[], [1], [2], [1, 2]]
//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}`);
class Timer{start(){this.startTime = Date.now();}stop(){const dt = Date.now() - this.startTime;console.log(dt);return dt;}getExecTime(fun, asynchronous){return asynchronous ? this.getAsyncExecTime(fun) : this.getSyncExecTime(fun);}getSyncExecTime(fun){this.start();fun();return this.stop();}async getAsyncExecTime(fun){this.start();await fun();return this.stop();}static average(fun, numTimes, asynchronous = false){const times = [];const promises = [];let timer = new Timer();if(asynchronous){for(let i = 0; i < numTimes; i++){timer.getAsyncExecTime(fun);}}else{for(let i = 0; i < numTimes; i++){timer.getSyncExecTime(fun);}}return (times => times.reduce(((sum, acc) => sume + acc), 0) / times.length);}static async timeAsync(fun, numTimes){if(numTimes <= 1) return new Timer().getAsyncExecTime(fun);const promises = [];let timer = new Timer(true);for(let i = 0; i < numTimes; i++){promises.push(fun().catch((e)=>{}));}try{await Promise.all(promises).catch((e)=>{});}catch(e){//do absolutely nothing}return timer.stop();}constructor(start = false){if(start) this.start();}}
let variableSet = JSON.parse('["parent","opener","top","length","frames","closed","location","self","window","document","name","customElements","history","locationbar","menubar","personalbar","scrollbars","statusbar","toolbar","status","frameElement","navigator","origin","external","screen","innerWidth","innerHeight","scrollX","pageXOffset","scrollY","pageYOffset","visualViewport","screenX","screenY","outerWidth","outerHeight","devicePixelRatio","clientInformation","screenLeft","screenTop","defaultStatus","defaultstatus","styleMedia","onsearch",&qu...find","webkitRequestAnimationFrame","webkitCancelAnimationFrame","fetch","btoa","atob","setTimeout","clearTimeout","setInterval","clearInterval","createImageBitmap","close","focus","blur","postMessage","onappinstalled","onbeforeinstallprompt","crypto","indexedDB","webkitStorageInfo","sessionStorage","localStorage","chrome","onpointerrawupdate","speechSynthesis","webkitRequestFileSystem","webkitResolveLocalFileSystemURL","openDatabase","variableSet","TEMPORARY","PERSISTENT","addEventListener","removeEventListener","dispatchEvent"]');let answer = [];for(let v in this) if(!variableSet.includes(v)) answer.push(v);console.log(answer);
import { configureStore } from "@reduxjs/toolkit";import { combineReducers } from "redux";import profile from "./profile";import auth from "./auth";import alert from "./alert";const reducer = combineReducers({profile,auth,alert,});const store = configureStore({ reducer });export default store;
const copyToClipboard = str => {const el = document.createElement('textarea');el.value = str;el.setAttribute('readonly', '');el.style.position = 'absolute';el.style.left = '-9999px';document.body.appendChild(el);const selected =document.getSelection().rangeCount > 0? document.getSelection().getRangeAt(0): false;el.select();document.execCommand('copy');document.body.removeChild(el);if (selected) {document.getSelection().removeAllRanges();document.getSelection().addRange(selected);}};copyToClipboard('Lorem ipsum'); // 'Lorem ipsum' copied to clipboard.