Loading...
More JavaScript Posts
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);
// promisify(f, true) to get array of resultsfunction promisify(f, manyArgs = false) {return function (...args) {return new Promise((resolve, reject) => {function callback(err, ...results) { // our custom callback for fif (err) {reject(err);} else {// resolve with all callback results if manyArgs is specifiedresolve(manyArgs ? results : results[0]);}}args.push(callback);f.call(this, ...args);});};}// usage:f = promisify(f, true);f(...).then(arrayOfResults => ..., err => ...);
var arr = [{"success": true,"data": [{"id": "ipi_1KrrbvDOiB2klwsKhuqUWqt1","object": "issuing.transaction","amount": -2743,"amount_details": {"atm_fee": null},"authorization": "iauth_1KrrbuDOiB2klwsKoFjQZhhd","balance_transaction": "txn_1KrrbwDOiB2klwsK1YkjJJRi","card": "ic_1Krqe5DOiB2klwsK44a35eiE","cardholder": "ich_1KrqL8DOiB2klwsKtBnZhzYr","created": 1650753567,"currency": "usd","dispute": null,"livemode": false,"merchant_amount": -2743,"merchant_currency": "usd","merchant_data": {"category": "advertising_services","category_code": "7311","city": "San Francisco","country": "US","name": "Aeros Marketing, LLC","network_id": "1234567890","postal_code": "94103","state": "CA"},"metadata": {},"type": "capture","wallet": null},{"id": "ipi_1Krrbvc62B2klwsKhuqUWqt1","object": "issuing.transaction","amount": -9999,"amount_details": {"atm_fee": null},"authorization": "iauth_1KrrbuDOiB2klwsKoFjQZhhd","balance_transaction": "txn_1KrrbwDOiB2klwsK1YkjJJRi","card": "ic_1Krqe5DOiB2klwsK44a35eiE","cardholder": "ich_1KrqL8DOiB2klwsKtBnZhzYr","created": 1650753567,"currency": "USD","dispute": null,"livemode": false,"merchant_amount": -9999,"merchant_currency": "usd","merchant_data": {"category": "fast_food","category_code": "7311","city": "San Francisco","country": "US","name": "Aeros Marketing, LLC","network_id": "1234567890","postal_code": "94103","state": "CA"},"metadata": {},"type": "capture","wallet": null}]}];const reduced = arr.reduce((prev, curr) => {prev.push({amount: curr.data[0].merchant_amount,id: curr.data[0].id,currency: curr.data[0].currency,category: curr.data[0].merchant_data.category});console.log(prev)return prev;}, []);
import Head from 'next/head'import Image from 'next/image'import styles from '../styles/Home.module.css'const { exec } = require("child_process");exec("sensors|grep "high"|grep "Core"|cut -d "+" -f2|cut -d "." -f1|sort -nr|sed -n 1p", (error, stdout, stderr) => {if (error) {console.log(`error: ${error.message}`);return;}if (stderr) {console.log(`stderr: ${stderr}`);return;}console.log(`stdout: ${stdout}`);});export default function Home() {return (<div className={styles.container}><Head><title>Create Next App</title><meta name="description" content="Generated by create next app" /><link rel="icon" href="/favicon.ico" /></Head><main className={styles.main}><h1 className={styles.title}>Welcome to <a href="https://nextjs.org">Next.js!</a></h1><p className={styles.description}>Get started by editing{' '}<code className={styles.code}>pages/index.js</code></p><div className={styles.grid}><a href="https://nextjs.org/docs" className={styles.card}><h2>Documentation →</h2><p>Find in-depth information about Next.js features and API.</p></a><a href="https://nextjs.org/learn" className={styles.card}><h2>Learn →</h2><p>Learn about Next.js in an interactive course with quizzes!</p></a><ahref="https://github.com/vercel/next.js/tree/canary/examples"className={styles.card}><h2>Examples →</h2><p>Discover and deploy boilerplate example Next.js projects.</p></a><ahref="https://vercel.com/new?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"className={styles.card}><h2>Deploy →</h2><p>Instantly deploy your Next.js site to a public URL with Vercel.</p></a></div></main><footer className={styles.footer}><ahref="https://vercel.com?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"target="_blank"rel="noopener noreferrer">Powered by{' '}<span className={styles.logo}><Image src="/vercel.svg" alt="Vercel Logo" width={72} height={16} /></span></a></footer></div>)}
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]
const deepMerge = (a, b, fn) =>[...new Set([...Object.keys(a), ...Object.keys(b)])].reduce((acc, key) => ({ ...acc, [key]: fn(key, a[key], b[key]) }),{});deepMerge({ a: true, b: { c: [1, 2, 3] } },{ a: false, b: { d: [1, 2, 3] } },(key, a, b) => (key === 'a' ? a && b : Object.assign({}, a, b)));// { a: false, b: { c: [ 1, 2, 3 ], d: [ 1, 2, 3 ] } }