Skip to content

Instantly share code, notes, and snippets.

@graynun
graynun / 10_4_voyageRating.js
Last active July 27, 2020 12:12
10.4. 조건부 로직을 다형성으로 바꾸기
const voyage = {zone: "서인도", length: 10};
const history = [
{zone: "동인도", profit: 5},
{zone: "서인도", profit: 15},
{zone: "중국", profit: -2},
{zone: "서아프리카", profit: 7},
];
const myRating = rating(voyage, history);
@graynun
graynun / 10_4_birds.js
Last active July 27, 2020 11:36
Replace Conditional with Polymorphism
function plumages(birds) {
return new Map(birds
.map(b => creaetBird(b))
.map(bird => [bird.name, b.plumage])
);
}
function speeds(birds) {
return new Map(birds
.map(b => creaetBird(b))
@graynun
graynun / 10_4_birds.js
Created July 27, 2020 11:29
Replace Conditional with Polymorphism
function plumages(birds) {
return new Map(birds.map(b => [b.name, plumage(b)]));
}
function speeds(birds) {
return new Map(birds.map(b => [b.name, airSpeedVelocity(b)]));
}
function plumage(bird) {
switch (bird.type) {
@graynun
graynun / pre-commit.sh
Created April 3, 2017 06:00
pre-commit hook for eslint in Knowre
#!/bin/sh
ESLINT="$(git rev-parse --show-toplevel)/node_modules/.bin/eslint"
if [[ ! -x "$ESLINT" ]]; then
echo "\t\033[41mPlease install ESlint\033[0m (npm i --save --save-exact --dev eslint)"
exit 1
fi
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep ".jsx\{0,1\}$"| grep -v "node_modules")