• Nov 19, 2022 •CodeCatch
0 likes • 1 view
let nums = [1,2,3,1] var containsDuplicate = function(nums) { let obj = {}; for(let i =0; i< nums.length; i++){ if(obj[nums[i]]){ obj[nums[i]] += 1; return true; }else{ obj[nums[i]] = 1; } } return false; }; console.log(containsDuplicate(nums));
• Jul 13, 2025 •West
const express = require('express') const app = express() const port = 3000 app.get('/', (req, res) => { res.send('Hello World!') }) app.listen(port, () => { console.log(`Example app listening on port ${port}`) })
0 likes • 3 views
const euclideanDistance = (a, b) => Math.hypot(...Object.keys(a).map(k => b[k] - a[k])); euclideanDistance([1, 1], [2, 3]); // ~2.2361 euclideanDistance([1, 1, 1], [2, 3, 2]); // ~2.4495
• Nov 18, 2022 •AustinLeath
0 likes • 2 views
var d = new Date(); var d = new Date(milliseconds); var d = new Date(dateString); var d = new Date(year, month, day, hours, minutes, seconds, milliseconds);
const levenshteinDistance = (s, t) => { if (!s.length) return t.length; if (!t.length) return s.length; const arr = []; for (let i = 0; i <= t.length; i++) { arr[i] = [i]; for (let j = 1; j <= s.length; j++) { arr[i][j] = i === 0 ? j : Math.min( arr[i - 1][j] + 1, arr[i][j - 1] + 1, arr[i - 1][j - 1] + (s[j - 1] === t[i - 1] ? 0 : 1) ); } } return arr[t.length][s.length]; }; levenshteinDistance('duck', 'dark'); // 2
const flat = arr => [].concat.apply([], arr.map(a => Array.isArray(a) ? flat(a) : a)); // Or const 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-flat const flat = arr => arr.flat(); // Example flat(['cat', ['lion', 'tiger']]); // ['cat', 'lion', 'tiger']