Skip to content

Instantly share code, notes, and snippets.

View nickangtc's full-sized avatar

Nick Ang nickangtc

View GitHub Profile
@nickangtc
nickangtc / iterm2-solarized.md
Created May 11, 2018 02:02 — forked from kevin-smets/iterm2-solarized.md
iTerm2 + Oh My Zsh + Solarized color scheme + Meslo powerline font + [Powerlevel9k] - (macOS)

Default

Default

Powerlevel9k

Powerlevel9k

@nickangtc
nickangtc / nativeJavaScript.js
Created May 10, 2018 08:14 — forked from alexhawkins/nativeJavaScript.js
Implementation of Native JavaScript Methods (forEach, Map, Filter, Reduce, Every, Some)
'use strict';
/*****************NATIVE forEACH*********************/
Array.prototype.myEach = function(callback) {
for (var i = 0; i < this.length; i++)
callback(this[i], i, this);
};
//tests
@nickangtc
nickangtc / homemade-each-reduce.js
Last active April 26, 2018 08:35
Homemade version of the built-in forEach() and reduce() in JavaScript
/**
* each()
*
* Apply an action to every item in an array.
*/
const list = [1, 2, 3];
const each = function (array, action) {
for (let i = 0; i < array.length; i++) {
action(array[i]);
@nickangtc
nickangtc / type-error-handling-conditional-vs-try-except.py
Last active April 16, 2018 06:19
For discussing the best approach for handling type errors in Python 3
def increment_list_by(list, num):
'''Increment all items in a list by `num`
provided all items are `int` types.
Return modified list if successful, or original list otherwise.'''
incremented_list = []
# =============
# Note: below are 2 separate approaches to implement this function
# =============
@nickangtc
nickangtc / layout-engine.js
Last active February 6, 2018 15:33
Layout Engine (coding challenge)
/*
* Complete the function below.
*
* Sample input 1: ['10 0 0 I love monkeys.']
* Sample output 1 (dashes denote trailing spaces):
* ---I love ---
* ---monkeys. -
*
* Sample input 2: ['10 0 0 I love monkeys.', '20 0 0 Good times and bad times.']
* Sample output 2 (dashes denote trailing spaces):
@nickangtc
nickangtc / queue.js
Created December 25, 2017 04:33
Simple implementation of a Queue in JavaScript - with performance tests
/**
* ============================================
* CUSTOM IMPLEMENTATION OF QUEUE CLASS
* ============================================
*/
/**
* Implementation of Queue.
*/
class Queue {
@nickangtc
nickangtc / bubble-sort-javascript.js
Created December 3, 2017 14:01
Bubble sort implementation in JavaScript
/**
* Sort an array in ascending order.
* Delete null values before output.
* @param {number[]} array
* @return {number[]}
*/
function bubbleSort (array) {
var count = 0
var length = array.length
@nickangtc
nickangtc / binary-search-tree-javascript.js
Last active November 21, 2017 13:26
Binary search tree implemented in JavaScript (tree not balanced)
/**
* Binary search tree implementation in JavaScript.
*
* Note: the BST created here is a BST that is not "balanced,"
* meaning it has a lot of nodes on one side,
* which degrades the BST's O(log n) time complexity.
*
* Note 2: I'll be adding a balancing function in another snippet.
*/
@nickangtc
nickangtc / binary-search-javascript.js
Last active October 24, 2018 19:32
Binary search in JavaScript
/**
* Binary search in JavaScript.
*
* For detailed explanation about binary search
* read my original blog post:
* http://www.nickang.com/binary-search-javascript/
*/
function binarySearch(array, key) {
var lower = 0;
@nickangtc
nickangtc / linked-list.js
Last active June 15, 2022 04:37
Linked list in JavaScript
/**
* Read the original blog post for a detailed explanation!
* http://www.nickang.com/linked-list-explained-part-1/
* http://www.nickang.com/linked-list-implementation-part-2/
*/
/**
* Constructor functions
*/