Skip to content
{{ message }}

Instantly share code, notes, and snippets. 🥑
Life is like a prototype, just like JavaScript. So, keep betting on JavaScript!

# Rong Sen Ng motss

🥑
Life is like a prototype, just like JavaScript. So, keep betting on JavaScript!
Created Dec 24, 2020
Switch to ZSH Shell in Bash
View switch-to-zsh-in-bash.md
```if test -t 1; then
exec zsh
fi```
Last active Oct 22, 2020
Find the sum of 2 smallest numbers
View find-sum-of-2-smallest-numbers.js
 function findSmallestSum(arr) { const len = arr.length; if (!len) return 0; if (len === 1) return arr; if (len === 2) return arr + arr; // f - first, s - second let [f, s] = arr; let sum = f + s;
Created Nov 19, 2019
VSCode Firefox Quantum Theme custom settings.json
View vscode-ff-custom-settings.json
 { "workbench.colorCustomizations": { "editor.selectionBackground": "#2179775c", "editor.background": "#0a0a0a" }, "workbench.colorTheme": "Firefox Quantum Dark" }
Created Sep 11, 2019
Create social media share button by customizable link
View create-social-media-share-button-by-customizable-link.js
Created Sep 3, 2019
Alternating characters
View alternating-characters.js
 // 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; let count = 0; let countA = lastChar === 'a' ? 1 : 0;
Created Aug 30, 2019
Pascal's triangle with n level
View pascals-triangle-with-n-level.js
 // 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 ; if (level === 2) return [1, 1]; const d = Array.from(Array(level), () => []);
Last active Aug 30, 2019
Moar dynamic programming
View min-steps-to-one.js
 // 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.
Last active Aug 29, 2019
Sorting
View insertion-sort.js
 // 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
Last active Jul 28, 2019
Sorting algorithms
View quick-sort.js
 { // Reference: https://bit.ly/2yjWDeY // Time complexity: O(n log n) on average or O(n^2) for worst-case // Space complexity: O(n) function quickSort(list) { if (list.length < 2) return list; const left = []; const right = [];
Last active Jul 12, 2019
According to ECMAScript's specs, it explains why null == undefined
View null-equals-undefined.js
 // http://www.ecma-international.org/ecma-262/5.1/#sec-11.9.3 // http://es5.github.io/#x11.9.3 // Abstract/ loose equality comparison will do type coercion // While strict equality comparison will compare the types null == undefined; // true