Skip to content

Instantly share code, notes, and snippets.

View dhwang's full-sized avatar
💭
I may be slow to respond.

Darren Hwang dhwang

💭
I may be slow to respond.
  • San Jose
View GitHub Profile
@dhwang
dhwang / how-to-squash-commits-in-git.md
Created September 1, 2021 16:44 — forked from patik/how-to-squash-commits-in-git.md
How to squash commits in git

Squashing Git Commits

The easy and flexible way

This method avoids merge conflicts if you have periodically pulled master into your branch. It also gives you the opportunity to squash into more than 1 commit, or to re-arrange your code into completely different commits (e.g. if you ended up working on three different features but the commits were not consecutive).

Note: You cannot use this method if you intend to open a pull request to merge your feature branch. This method requires committing directly to master.

Switch to the master branch and make sure you are up to date:

@dhwang
dhwang / uniqueBy.js
Created May 24, 2024 23:50
uniqueBy
const uniqBy = (arr, predicate) => {
if (!Array.isArray(arr)) { return []; }
const cb = typeof predicate === 'function' ? predicate : (o) => o[predicate];
const pickedObjects = arr
.filter(item => item)
.reduce((map, item) => {
const key = cb(item);
@dhwang
dhwang / chainFunctions.js
Last active July 4, 2025 17:03
chain function execution using reduce
/**
* chainFunctions() creates a function that returns the result of invoking the given list of functions with
* where each successive invocation is supplied the return value of the previous.
* @example
* const replacer = chainFunctions([replaceNewLine, replaceEntities, replaceMultiSpace]);
* const cleanStr = replacer(originalString);
* @param {Function[]} fns - list of functions to be invoked
* @returns {*} function execution result
*/