Skip to content

Instantly share code, notes, and snippets.

View aire-con-gas's full-sized avatar

Dave Hong aire-con-gas

View GitHub Profile
const findSubstr = (needle, haystack) => {
let atIdx = -1;
let found = false;
const needleArr = needle.split('');
const haystackArr = haystack.split('');
for(let i = 0; i <= haystackArr.length; i++) {
found = true;
if (needle[0] === haystackArr[i]) {
for(let j = 0; j <= needleArr.length; j++) {
const longestSubstrLen = (s) => {
const originalStrLen = s.length;
const originalStrArr = s.split('');
let subStrLen = 0;
const lookupMap = {};
for(let j=0, i=0; j < originalStrLen; j++) {
const currChar = originalStrArr[j];
console.log('i', i);
const maxProfit = (prices = []) => {
let minPrice = Number.MAX_SAFE_INTEGER;
let maxProfit = 0;
prices.forEach(price => {
if (price < minPrice) {
minPrice = price;
} else if (price - minPrice > maxProfit) {
maxProfit = price - minPrice;
}
npm i --save-dev webpack style-loader css-loader html-webpack-plugin webpack-dev-server babel-preset-env babel-loader babel-core less less-loader eslint eslint-config-airbnb-base babel-eslint eslint-plugin-babel babel-preset-react
npm i eslint react
npm install -g webpack eslint-cli
touch webpack.config.js
touch .babelrc
touch .eslintc
@aire-con-gas
aire-con-gas / wordBreak.js
Created December 8, 2017 22:36
Break up words in a string
const wordBreak = (text = '', validWords = []) => {
const wordLookupPos = {};
function breakUpWord (text, validWords, offset) {
if (wordLookupPos[offset]) {
return wordLookupPos[offset];
}
const resultArr = [];
@aire-con-gas
aire-con-gas / findMedian.js
Created December 8, 2017 18:13
find median of two sorted arrays
const median = (A = [], B = []) => {
const m = A.length;
const n = B.length;
let iMin = 0;
let iMax = m;
let halfLength = Math.floor((m + n + 1) / 2);
let result = -1;
console.log('******* START ******');
@aire-con-gas
aire-con-gas / deepEqual.js
Created December 7, 2017 21:12
deepEqual
const deepEqual = (a, b) => {
const isEqual = (a, b) => (a === b);
const objCompare = (a, b) => {
for(let k in a) {
if (typeof b[k] === 'undefined') {
return false;
}
if (!isEqual(a[k], b[k])) {
return false;

Keybase proof

I hereby claim:

  • I am aire-con-gas on github.
  • I am soydave (https://keybase.io/soydave) on keybase.
  • I have a public key ASAvscibjQ-0mWFp5UfQejvfP8GqyBsRGlFPTxoVg9szugo

To claim this, I am signing this object:

@aire-con-gas
aire-con-gas / private.xml
Created July 26, 2016 16:42
Microsoft Sculpt Mouse for Mac
<?xml version="1.0"?>
<root>
<deviceproductdef>
<productname>SCULPT_MOBILE</productname>
<productid>0x07a2</productid>
</deviceproductdef>
<item>
<name>Windows Button to Mouse Button 4 (Microsoft Sculpt Mobile Mouse)</name>
<identifier>com.microsoft.mouse.sculpt_mobile.win_button</identifier>
/**
* @param {string} s
* @return {boolean}
*/
var canPermutePalindrome = function(s) {
var charTable = {},
charSet = {
'even': 0,
'odd': 0
},