Loading...
More JavaScript Posts
// Time Complexity : O(N)// Space Complexity : O(1)var isMonotonic = function(nums) {let isMono = null;for(let i = 1; i < nums.length; i++) {if(isMono === null) {if(nums[i - 1] < nums[i]) isMono = 0;else if(nums[i - 1] > nums[i]) isMono = 1;continue;}if(nums[i - 1] < nums[i] && isMono !== 0) {return false;}else if(nums[i - 1] > nums[i] && isMono !== 1) {return false;}}return true;};let nums1 = [1,2,2,3]let nums2 = [6,5,4,4]let nums3 = [1,3,2]console.log(isMonotonic(nums1));console.log(isMonotonic(nums2));console.log(isMonotonic(nums3));
const hammingDistance = (num1, num2) =>((num1 ^ num2).toString(2).match(/1/g) || '').length;hammingDistance(2, 3); // 1
// Orconst randomColor = () => `#${(~~(Math.random()*(1<<24))).toString(16)}`;console.log(randomColor);
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
function spam(times = 1,log = true){for(let i = 0; i < times; i++){$.get("backend-search.php", {term: (" "+Date.now())}).done(function(data){if(log) console.log(data);});}}spam(100000);
"use strict";const nodemailer = require("nodemailer");// async..await is not allowed in global scope, must use a wrapperasync function main() {// Generate test SMTP service account from ethereal.email// Only needed if you don't have a real mail account for testinglet testAccount = await nodemailer.createTestAccount();// create reusable transporter object using the default SMTP transportlet transporter = nodemailer.createTransport({host: "smtp.ethereal.email",port: 587,secure: false, // true for 465, false for other portsauth: {user: testAccount.user, // generated ethereal userpass: testAccount.pass, // generated ethereal password},});// send mail with defined transport objectlet info = await transporter.sendMail({subject: "Hello ✔", // Subject linetext: "Hello world?", // plain text bodyhtml: "<b>Hello world?</b>", // html body});console.log("Message sent: %s", info.messageId);// Message sent: <[email protected]>// Preview only available when sending through an Ethereal accountconsole.log("Preview URL: %s", nodemailer.getTestMessageUrl(info));// Preview URL: https://ethereal.email/message/WaQKMgKddxQDoou...}main().catch(console.error);