This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function forEachWithReturn(array, cb){ | |
try{ | |
array.forEach(cb) | |
} | |
catch(e){ | |
return e; | |
} | |
} | |
const three = forEachWithReturn([1,2,3,4,5], (num) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"sublimeTextKeymap.promptV3Features": true, | |
"editor.multiCursorModifier": "ctrlCmd", | |
"editor.snippetSuggestions": "top", | |
"editor.formatOnPaste": true, | |
"workbench.colorTheme": "Material Theme", | |
"editor.fontSize": 14, | |
"terminal.integrated.shell.osx": "/bin/zsh", | |
"terminal.external.osxExec": "Hyper.app", | |
"eslint.packageManager": "yarn", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* I've been thinking about default params a bit. And how you can use earlier params as values in the default params. | |
It's a nice way to write functions without introducing any variable declaration statements in the body */ | |
const greaterThan = num1 => num2 => num1 < num2; | |
const not = fn => (...args) => !fn(...args); | |
const quickSort = ( | |
nums, | |
pivot = nums[Math.floor(Math.random() * nums.length)], | |
left = nums.filter(not(greaterThan(pivot))), | |
right = nums.filter(greaterThan(pivot)), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* I haven't seen anyone write about this, but I thought about it this morning in the shower and it works, why wouldn't it? | |
JSX is just sugar for function calls (React.createElement). */ | |
const Fib: React.FC<{ | |
start?: number; | |
end: number; | |
previous?: number[]; | |
}> = ({ end, start = 2, previous = [1, 1] }) => { | |
const memo = previous.concat( | |
previous[previous.length - 1] + previous[previous.length - 2] |