Skip to content

Instantly share code, notes, and snippets.

View johntran's full-sized avatar
🌈
Make it last forever, FRIENDSHIP NEVER ENDS

johntran

🌈
Make it last forever, FRIENDSHIP NEVER ENDS
View GitHub Profile
function map(arr, func) {
return arr.map(func);
}
// IF you are super particular about ordering
function parseCSV(csv) {
var peopleArray = csv.split('\n');
var peopleArrayWithSplitNameElements = map(peopleArray, function(str){
return str.split(',');
})
function foo(a) {
return a()
}
function bar(a) {
return 1
}
// I am passing bar in to foo. bar is a callback function to foo
function woof() {
@johntran
johntran / prettier.js
Last active April 22, 2019 19:09
prettier everything
./node_modules/.bin/prettier --single-quote --trailing-comma all --write "{,!(node_modules)/**/}*.js"
/**
Given two sorted arrays, merge them into one big sorted array
Ex:
merge([1,3,5],[2,4,6])
returns [1,2,3,4,5,6]
You cannot use array.sort().
Try to solve this in O(n+m) runtime.
Where n is the length of the first array
and m is the length of the second array.
/**
https://lodash.com/docs/4.17.4#memoize
Create a function that saves previous results of past calls.
Example:
function add(x,y) {
return x + y
}
const memoizedAdd = memoize(add);
/**
https://lodash.com/docs/4.17.4#flattenDeep
Recursively flattens array.
_.flattenDeep([1, [2, [3, [4]], 5]]);
// => [1, 2, 3, 4, 5]
Even if I nest an element 100 levels deep, it should still flatten it.
*/
{
"scripts": {
"lint": "eslint server",
"lint:fix": "npm run lint -- --fix",
"prettier":
"./node_modules/.bin/prettier --single-quote --trailing-comma all --write \"{,!(node_modules|build|dist|flow-typed)/**/}*.js\"",
"prettierTS":
"./node_modules/.bin/prettier --single-quote --trailing-comma all --write \"{,!(node_modules|build|dist|flow-typed)/**/}*.ts\"",
"prettierTSX":
"./node_modules/.bin/prettier --single-quote --trailing-comma all --write \"{,!(node_modules|build|dist|flow-typed)/**/}*.tsx\"",
const foobar = factors =>
factors.map(factor =>
factors.map(secondFactor =>
factor * secondFactor
)
);
var foobar = function(factors) {
return factors.map(function(factor) {
return factors.map(function (secondFactor) {
function getBillingAddress({
firstName,
lastName,
street,
addressLineTwo,
city,
state,
zip,
} ) {
return {
@johntran
johntran / EditPaymentDialog.js
Last active May 24, 2018 03:55
Feature Flags: React 16 Context + TypeScript
import * as React from 'react';
import {withFeatureFlags} from './FeatureFlag'
@withFeatureFlags(['TEMP_20180523_123_DELETE_PAYMENTS'])
class EditPaymentDialog extends React.Component<{}, {}> {
render() {
const { featureFlags } = this.props;
const { TEMP_20180523_123_DELETE_PAYMENTS } = featureFlags;
if (TEMP_20180523_123_DELETE_PAYMENTS) return <div />;
return null;