Loading...
More JavaScript Posts
alert("bruh")
// `date` is a `Date` objectconst formatYmd = date => date.toISOString().slice(0, 10);// ExampleformatYmd(new Date()); // 2020-05-06
const union = (...arr) => [...new Set(arr.flat())];// Exampleunion([1, 2], [2, 3], [3]); // [1, 2, 3]
const permutations = arr => {if (arr.length <= 2) return arr.length === 2 ? [arr, [arr[1], arr[0]]] : arr;return arr.reduce((acc, item, i) =>acc.concat(permutations([...arr.slice(0, i), ...arr.slice(i + 1)]).map(val => [item,...val,])),[]);};permutations([1, 33, 5]);// [ [1, 33, 5], [1, 5, 33], [33, 1, 5], [33, 5, 1], [5, 1, 33], [5, 33, 1] ]
const toFixed = (n, fixed) => ~~(Math.pow(10, fixed) * n) / Math.pow(10, fixed);// ExamplestoFixed(25.198726354, 1); // 25.1toFixed(25.198726354, 2); // 25.19toFixed(25.198726354, 3); // 25.198toFixed(25.198726354, 4); // 25.1987toFixed(25.198726354, 5); // 25.19872toFixed(25.198726354, 6); // 25.198726
/*** @param {number[]} nums* @return {boolean}*/var containsDuplicate = function(nums) {return new Set(nums).size !== nums.length};