Loading...
More JavaScript Posts
# Acronyms## Computer Numerical Control (CNC)- Typicalldfdfsdffdafdasgfdgfgfdfdafdasfdafda
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)];};quickSort([1, 6, 1, 5, 3, 2, 1, 4]); // [1, 1, 1, 2, 3, 4, 5, 6]
// Get the text that the user has selectedconst getSelectedText = () => window.getSelection().toString();getSelectedText();
const MongoClient = require('mongodb').MongoClient;const assert = require('assert');// Connection URLconst url = 'mongodb://localhost:27017';// Database Nameconst dbName = 'myproject';// Use connect method to connect to the serverMongoClient.connect(url, function(err, client) {assert.equal(null, err);console.log("Connected successfully to server");const db = client.db(dbName);client.close();});
// `date` is a `Date` objectconst formatYmd = date => date.toISOString().slice(0, 10);// ExampleformatYmd(new Date()); // 2020-05-06
const binarySearch = (arr, item) => {let l = 0,r = arr.length - 1;while (l <= r) {const mid = Math.floor((l + r) / 2);const guess = arr[mid];if (guess === item) return mid;if (guess > item) r = mid - 1;else l = mid + 1;}return -1;};binarySearch([1, 2, 3, 4, 5], 1); // 0binarySearch([1, 2, 3, 4, 5], 5); // 4binarySearch([1, 2, 3, 4, 5], 6); // -1