Loading...
More JavaScript Posts
arr = [] // empty arrayconst isEmpty = arr => !Array.isArray(arr) || arr.length === 0;// ExamplesisEmpty([]); // trueisEmpty([1, 2, 3]); // false
const getTimezone = () => Intl.DateTimeFormat().resolvedOptions().timeZone;// ExamplegetTimezone();
//JavaScript program to swap two variables//take input from the userslet a = prompt('Enter the first variable: ');let b = prompt('Enter the second variable: ');//using destructuring assignment[a, b] = [b, a];console.log(`The value of a after swapping: ${a}`);console.log(`The value of b after swapping: ${b}`);
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;}, []);
const mongoose = require('mongoose')const UserSchema = new mongoose.Schema({username: {type: String,required: true},email: {type: String,unique: true,required: true},password: {type: String,required: true},date: {type: Date,default: Date.now}})module.exports = User = mongoose.model('user', UserSchema)
class LinkedList {constructor() {this.nodes = [];}get size() {return this.nodes.length;}get head() {return this.size ? this.nodes[0] : null;}get tail() {return this.size ? this.nodes[this.size - 1] : null;}insertAt(index, value) {const previousNode = this.nodes[index - 1] || null;const nextNode = this.nodes[index] || null;const node = { value, next: nextNode };if (previousNode) previousNode.next = node;this.nodes.splice(index, 0, node);}insertFirst(value) {this.insertAt(0, value);}insertLast(value) {this.insertAt(this.size, value);}getAt(index) {return this.nodes[index];}removeAt(index) {const previousNode = this.nodes[index - 1];const nextNode = this.nodes[index + 1] || null;if (previousNode) previousNode.next = nextNode;return this.nodes.splice(index, 1);}clear() {this.nodes = [];}reverse() {this.nodes = this.nodes.reduce((acc, { value }) => [{ value, next: acc[0] || null }, ...acc],[]);}*[Symbol.iterator]() {yield* this.nodes;}}const list = new LinkedList();list.insertFirst(1);list.insertFirst(2);list.insertFirst(3);list.insertLast(4);list.insertAt(3, 5);list.size; // 5list.head.value; // 3list.head.next.value; // 2list.tail.value; // 4[...list.map(e => e.value)]; // [3, 2, 1, 5, 4]list.removeAt(1); // 2list.getAt(1).value; // 1list.head.next.value; // 1[...list.map(e => e.value)]; // [3, 1, 5, 4]list.reverse();[...list.map(e => e.value)]; // [4, 5, 1, 3]list.clear();list.size; // 0