Loading...
More JavaScript Posts
const flat = arr => [].concat.apply([], arr.map(a => Array.isArray(a) ? flat(a) : a));// Orconst flat = arr => arr.reduce((a, b) => Array.isArray(b) ? [...a, ...flat(b)] : [...a, b], []);// Or// See the browser compatibility at https://caniuse.com/#feat=array-flatconst flat = arr => arr.flat();// Exampleflat(['cat', ['lion', 'tiger']]); // ['cat', 'lion', 'tiger']
const express = require('express')const app = express()const port = 3000app.get('/', (req, res) => {res.send('Hello World!')})app.listen(port, () => {console.log(`Example app listening on port ${port}`)})
function sortNumbers(arr) {return arr.slice().sort((a, b) => a - b);}const unsortedArray = [4, 1, 9, 6, 3, 5];const sortedArray = sortNumbers(unsortedArray);console.log("Unsorted Numbers:", unsortedArray);console.log("\n");console.log("Sorted Numbers:", sortedArray);
const insertionSort = arr =>arr.reduce((acc, x) => {if (!acc.length) return [x];acc.some((y, j) => {if (x <= y) {acc.splice(j, 0, x);return true;}if (x > y && j === acc.length - 1) {acc.splice(j + 1, 0, x);return true;}return false;});return acc;}, []);insertionSort([6, 3, 4, 1]); // [1, 3, 4, 6]
var invertTree = function(root) {const reverseNode = node => {if (node == null) {return null}reverseNode(node.left);reverseNode(node.right);let holdLeft = node.left;node.left = node.right;node.right = holdLeft;return node;}return reverseNode(root);};
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);