Skip to content

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!
Block or report user

Report or block motss

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@motss
motss / vscode-ff-custom-settings.json
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"
}
@motss
motss / create-social-media-share-button-by-customizable-link.js
Created Sep 11, 2019
Create social media share button by customizable link
View create-social-media-share-button-by-customizable-link.js
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[0];
let count = 0;
let countA = lastChar === 'a' ? 1 : 0;
@motss
motss / pascals-triangle-with-n-level.js
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 [1];
if (level === 2) return [1, 1];
const d = Array.from(Array(level), () => []);
@motss
motss / min-steps-to-one.js
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.
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
@motss
motss / quick-sort.js
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 = [];
@motss
motss / null-equals-undefined.js
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
@motss
motss / binary-search-iterative.js
Last active Jul 23, 2019
Binary Search (recursive or iterative implementations)
View binary-search-iterative.js
function bsr(arr, m) {
let l = 0;
let r = arr.length - 1;
while (l <= r) {
const mid = (l + (r - l) / 2) | 0;
const val = arr[mid];
if (val === m) return mid;
if (m > val) l = mid + 1;
@motss
motss / flight-search-form.md
Created Jul 10, 2019
Attempt to recreate flight search form on Google Flights
View flight-search-form.md

Attempt to recreate flight search form on Google Flights

Demo URL

You can’t perform that action at this time.