/** @see microsoft/WSL#1724 (comment) */
if test -t 1; then
zsh
fi
// a = 1; b = a - 1; b = b - 100; b * a - 100 | |
// split('; '); | |
// a=1 | |
// b=a-1 | |
// b=b-100 | |
// b*a-100 | |
// a=1 | |
// a 1 = |
function tryParseUrl(url) { | |
try { | |
const u = new URL(url); | |
return u; | |
} catch (error) { | |
console.error(error); | |
return ''; | |
} | |
} |
/** @see microsoft/WSL#1724 (comment) */
if test -t 1; then
zsh
fi
function findSmallestSum(arr) { | |
const len = arr.length; | |
if (!len) return 0; | |
if (len === 1) return arr[0]; | |
if (len === 2) return arr[0] + arr[1]; | |
// f - first, s - second | |
let [f, s] = arr; | |
let sum = f + s; |
{ | |
"workbench.colorCustomizations": { | |
"editor.selectionBackground": "#2179775c", | |
"editor.background": "#0a0a0a" | |
}, | |
"workbench.colorTheme": "Firefox Quantum Dark" | |
} |
// Time complexity: O(n) where n is the number of characters. | |
// Space complexity: O(1) for a few variables. | |
function alternatingCharacters(x) { | |
const len = x.length; | |
if (len < 2) return 0; | |
let lastChar = x[0]; | |
let count = 0; | |
let countA = lastChar === 'a' ? 1 : 0; |
// Time complexity: O(n ^ 2) where is the number of levels and | |
// another n is for the number of elements in each level. | |
// Space complexity: O(2n + 1) to hold all elements, which is linear space. | |
function pascalTriangle(level) { | |
if (level === 0) return []; | |
if (level === 1) return [1]; | |
if (level === 2) return [1, 1]; | |
const d = Array.from(Array(level), () => []); |
// Given an integer n, find the minimum number of steps | |
// to reach integer 1. | |
// At each step, you can: | |
// * n - 1 | |
// * n / 2, if it is divisble by 2 | |
// * n / 3, if it is divisble by 3 | |
// n = 0: 0 // base case 0. | |
// n = 1: 0 // base case 1. | |
// n = 2: 1 // base case 2. |
// i | |
// j | |
// 4 2 1 3 6 0 | |
// i | |
// j | |
// 4 2 1 3 6 0 | |
// 2 4 1 3 6 0 # 2 < 4 | |
// i |