memostack
article thumbnail
정말 쉽게 yarn berry와 typescript 환경 설정하기
Frontend/Typescript 2022. 12. 28. 23:03

yarn berry를 사용하여 typescript 개발 환경을 만들어보자 yarn berry 설정 패키지 매니저 버전을 yarn berry로 변경하기 위해, 아래 명령어를 수행한다. yarn set version berry 위 명령어가 수행이 되면, .yarn 폴더, .yarnrc.yml 파일이 생성된다. 프로젝트 생성 yarn init 명령어를 사용하여, 프로젝트를 생성한다. yarn init -y package.json을 보면 packageManager 부분이 yarn@3.x.x과 설정되어 있는 것을 확인 할 수 있다. (3버전이 berry) { ... "packageManager": "yarn@3.3.1", ... } typescript 설정 기본적으로 프로젝트가 설정되었으니 typescript를 ..

article thumbnail
백준 11654번 / 아스키 코드 (nodejs 알고리즘 풀이)
Algorithm/Beakjoon 2022. 9. 2. 21:27

문제의 저작권은 백준 알고리즘(https://www.acmicpc.net/)에 있습니다 문제 풀이 charCodeAt() 함수를 사용하면, 해당 문자열의 ascii 코드 값을 구할 수 있다. 단순히 charCodeAt() 함수로 변환해주면 되는 간단한 문제이다. const solution = (input) => input.charCodeAt(0); const print = (input) => console.log(solution(input + '')); process.stdin.on('data', print); 전체 코드 https://github.com/bluemiv/Algorithm/blob/master/baekjoon/nodejs/src/ex11/ex11654.js GitHub - bluemiv/A..

article thumbnail
백준 1316번 / 그룹 단어 체커 (nodejs 알고리즘 풀이)
Algorithm/Beakjoon 2022. 9. 1. 22:06

문제의 저작권은 백준 알고리즘(https://www.acmicpc.net/)에 있습니다 문제 풀이 전체 코드 const solution = (input) => { const ls = input.slice(1, +input[0] + 1); return ls.reduce((cnt, l) => { const visit = {}; const cl = l.split(''); for (let i = 0; i < cl.length; i++) { const c = cl[i]; if (!visit[c]) { visit[c] = true; } else { if (c !== cl[i - 1]) { return cnt; } } } return cnt + 1; }, 0); }; const input = []; require('..

article thumbnail
백준 2908번 / 상수 (nodejs 알고리즘 풀이)
Algorithm/Beakjoon 2022. 8. 31. 21:19

문제의 저작권은 백준 알고리즘(https://www.acmicpc.net/)에 있습니다 문제 풀이 전체 코드 const solution = (input) => { const nums = input.split(' ').map((s) => +s.split('').reverse().join('')); return Math.max(...nums); }; require('readline') .createInterface(process.stdin, process.stdout) .on('line', (input) => console.log(solution(input))) .on('close', () => process.exit(0)); 상세 풀이 배열에 reverse() 함수를 사용하면, 배열의 원소를 역순으로 재정..

article thumbnail
백준 1152번 / 단어의 개수 (nodejs 알고리즘 풀이)
Algorithm/Beakjoon 2022. 8. 30. 21:16

문제의 저작권은 백준 알고리즘(https://www.acmicpc.net/)에 있습니다 문제 풀이 전체 코드 const solution = (input) => input.split(' ').filter((s) => !!s).length; require('readline') .createInterface(process.stdin, process.stdout) .on('line', (input) => { console.log(solution(input)); }) .on('close', () => { process.exit(0); }); 상세 풀이 단어를 구분하는 기준은 띄어쓰기 시작하는 부분부터 끝나는 부분이다. 즉, 빈 공백 ' '으로 split하여 개수를 카운팅하면 된다. 주의할 점으로는 문장의 맨 앞..

article thumbnail
백준 2675번 / 문자열 반복 (nodejs 알고리즘 풀이)
Algorithm/Beakjoon 2022. 8. 29. 20:55

문제의 저작권은 백준 알고리즘(https://www.acmicpc.net/)에 있습니다 문제 풀이 전체 코드 const solution = (input) => { return input .slice(1, input.length) .reduce((acc, l) => { const [n, str] = l.split(' '); acc.push(str.split('').reduce((acc, c) => acc + c.repeat(+n), '')); return acc; }, []) .join('\n'); }; const input = []; require('readline') .createInterface({ input: process.stdin }) .on('line', (line) => input.push(..

article thumbnail
typegraphql + typeorm + postgres을 사용하여 monorepo apollo server 구축
Backend/GraphQL 2022. 8. 28. 13:50

monorepo 프로젝트 구성 프로젝트의 디렉토를 생성해준다. mkdir typeorm-apollo-server-example yarn berry를 사용할 예정이기 때문에, 아래 명령어로 berry 버전으로 변경해준다. yarn set version berry 아래에서 apollo server를 오류없이 원활하게 구축하기 위해, .yarnrc.yml의 nodeLinker를 node-modules로 수정해준다. nodeLinker: node-modules yarnPath: .yarn/releases/yarn-3.2.3.cjs yarn init 명령어로 monorepo 프로젝트를 초기 설정한다. yarn init -y package.json이 생성이 되면, workspace 경로를 정의하고, 편의를 위해 s..

article thumbnail
백준 10818번 / 최소, 최대 (nodejs 알고리즘 풀이)
Algorithm/Beakjoon 2022. 8. 27. 20:48

문제의 저작권은 백준 알고리즘(https://www.acmicpc.net/)에 있습니다 문제 풀이 최댓값과 최솟값을 구하는 bulit-in 모듈인 Math 모듈을 사용하면 쉽게 구할 수 있다. 모듈 도움없이 반복문을 사용해서 풀어도 되긴하지만, 굳이 제공해주는 모듈을 사용안할 이유는 없다고 생각한다. const solution = (input) => { const list = input[1].split(' ').map((s) => +s); return [Math.min(...list), Math.max(...list)].join(' '); }; const input = []; require('readline') .createInterface({ input: process.stdin }) .on('line..

article thumbnail
apollo server와 knex를 이용하여 postgresql 연동하기 (with monorepo, typescript)
Backend/GraphQL 2022. 8. 26. 21:24

환경 nodejs: v16.15.1 (lts) yarn version: berry 프로젝트 구조: monorepo Framework: apollo-server-express 기타 사용 모듈: typescript, Knex DB: postgresql monorepo 프로젝트 생성 graphql 서버 구축 전에 yarn workspace를 활용하여 monorepo 프로젝트 생성을 한다. mkdir knex-apollo-server-example yarn berry를 사용하기 위해 버전을 변경한다. 그리고 yarn init 명령어로 프로젝트 초기 설정을 한다. yarn set version berry yarn init -y .yarnrc.yml에서 nodeLinker에 node-modules를 추가한다. no..

article thumbnail
백준 2941번 / 크로아티아 알파벳 (nodejs 알고리즘 풀이)
Algorithm/Beakjoon 2022. 8. 25. 21:32

문제의 저작권은 백준 알고리즘(https://www.acmicpc.net/)에 있습니다 문제 풀이 전체 코드 const solution = (input) => { const s = input.split(''); let cnt = 0; for (let i = 0; i < s.length; i++) { const c = s[i]; const nc = s[i + 1]; const nnc = s[i + 2]; if (c === 'd') { if (i + 2 < s.length && nc === 'z' && nnc === '=') { i += 2; } else if (i + 1 < s.length && nc === '-') { i++; } } else if (c === 'c' && i + 1 < s.length ..

article thumbnail
백준 5622번 / 다이얼 (nodejs 알고리즘 풀이)
Algorithm/Beakjoon 2022. 8. 24. 21:25

문제의 저작권은 백준 알고리즘(https://www.acmicpc.net/)에 있습니다 문제 풀이 전체 코드 const solution = (input) => { const dial = [...Array(26).keys()].reduce((acc, i) => { const n = 65 + i; const c = String.fromCharCode(n); if (n < 68) acc[c] = 2; else if (n < 71) acc[c] = 3; else if (n < 74) acc[c] = 4; else if (n < 77) acc[c] = 5; else if (n < 80) acc[c] = 6; else if (n < 84) acc[c] = 7; else if (n < 87) acc[c] = 8; e..

article thumbnail
백준 1157번 / 단어 공부 (nodejs 알고리즘 풀이)
Algorithm/Beakjoon 2022. 8. 21. 12:04

문제의 저작권은 백준 알고리즘(https://www.acmicpc.net/)에 있습니다 문제 풀이 전체 코드 const solution = (input) => { const en = new Array(26).fill(0); let max = Number.MIN_SAFE_INTEGER; input .toUpperCase() .split('') .forEach((c) => { const idx = c.charCodeAt() - 65; en[idx]++; max = max > en[idx] ? max : en[idx]; }); if (en.filter((n) => n === max).length > 1) return '?'; for (let i = 0; i < en.length; i++) { if (en[i]..

article thumbnail
백준 11720번 / 숫자의 합 (nodejs 알고리즘 풀이)
Algorithm/Beakjoon 2022. 8. 19. 21:33

문제의 저작권은 백준 알고리즘(https://www.acmicpc.net/)에 있습니다 문제 풀이 입력값을 각 문자로 나눠서 배열로 만든 뒤에 reduce()로 누적값을 구한다. 문자열 정수 값을 +연산자로 숫자 형태로 변환하여 합을 구한다. const solution = (input) => input[1].split('').reduce((acc, n) => +n + acc, 0); const input = []; require('readline') .createInterface({ input: process.stdin }) .on('line', (line) => input.push(line)) .on('close', (_) => { console.log(solution(input)); process.e..

article thumbnail
백준 10809번 / 알파벳 찾기 (nodejs 알고리즘 풀이)
Algorithm/Beakjoon 2022. 8. 17. 21:24

문제의 저작권은 백준 알고리즘(https://www.acmicpc.net/)에 있습니다 문제 풀이 전체 풀이 const solution = (input) => { const en = [...Array(26).keys()].map((_) => -1); input.split('').forEach((c, idx) => { const cIdx = c.charCodeAt(0) - 97; if (en[cIdx] === -1) { en[cIdx] = idx; } }); return en.join(' '); }; const print = (input) => console.log(solution(input + '')); process.stdin.on('data', print); 상세 설명 알파벳 개수 길이(a~z, 26..

article thumbnail
백준 1065번 / 한수 (nodejs 알고리즘 풀이)
Algorithm/Beakjoon 2022. 8. 16. 21:48

문제의 저작권은 백준 알고리즘(https://www.acmicpc.net/)에 있습니다 문제 풀이 const isHanNum = (n) => { if (n 0) { const curNum = t % 10; if (prevNum != null) { const curDelta = prevNum - curNum; if (delta != null && curDelta !== delta) { return false; } delta = curDelta; } prevNum = curNum; t = parseInt(t / 10); } return true; }; const solution = ..

article thumbnail
백준 4673번 / 셀프 넘버 (nodejs 알고리즘 풀이)
Algorithm/Beakjoon 2022. 8. 15. 21:06

문제의 저작권은 백준 알고리즘(https://www.acmicpc.net/)에 있습니다 문제 풀이 const d = (n) => { const answer = [n]; let t = n; while (t > 0) { answer.push(t % 10); t = parseInt(t / 10); } return answer.reduce((acc, n) => acc + n, 0); }; const solution = () => { const checkSelfNum = [...Array(10001).keys()].map((_) => true); [...Array(10000).keys()].forEach((i) => (checkSelfNum[d(i + 1)] = false)); return checkSelfNum..

article thumbnail
백준 4344번 / 평균은 넘겠지 (nodejs 알고리즘 풀이)
Algorithm/Beakjoon 2022. 8. 14. 13:17

문제의 저작권은 백준 알고리즘(https://www.acmicpc.net/)에 있습니다 문제 풀이 반 평균을 먼저 구한뒤에 각 학생의 점수를 하나씩 비교하여, 평균보다 크면 카운트를 증가시켜주도록 했다. const solution = (input) => { return [...Array(+input[0]).keys()] .map((idx) => { const list = input[idx + 1].split(' ').map((c) => +c); const studentCount = list[0]; const scores = list.slice(1, list.length); const avg = scores.reduce((acc, n) => acc + n, 0) / studentCount; return `..

article thumbnail
백준 8958번 / OX퀴즈 (nodejs 알고리즘 풀이)
Algorithm/Beakjoon 2022. 8. 13. 16:49

문제의 저작권은 백준 알고리즘(https://www.acmicpc.net/)에 있습니다 문제 풀이 한 글자씩 iteration을 하면서, X를 만나면 증가시켜줄 점수(score)를 0으로 초기화해준다. O를 만나면 점수(score) 값을 1씩 증가시켜주면서, 계속해서 총 합을 구하면 된다. const solution = (input) => { const n = +input[0]; return [...Array(n).keys()] .map((i) => { return input[i + 1].split('').reduce( (acc, c) => { if (c === 'X') { acc.score = 0; } else { acc.score += 1; acc.rs += acc.score; } return acc..

article thumbnail
백준 1546번 / 평균 (nodejs 알고리즘 풀이)
Algorithm/Beakjoon 2022. 8. 12. 21:27

문제의 저작권은 백준 알고리즘(https://www.acmicpc.net/)에 있습니다 문제 풀이 입력 받은 값을 조작하여 새로운 값을 만든 뒤, 평균을 구하는 간단한 문제이다. 오차 10^-2까지 허용하기 때문에 반올림과 같은 작업을 해줄 필요없다. const solution = (input) => { const nums = input[1].split(' ').map((s) => +s); const max = Math.max(...nums); return nums.reduce((acc, n) => acc + (n / max) * 100, 0) / nums.length; }; const input = []; require('readline') .createInterface({ input: process...

article thumbnail
백준 3052번 / 나머지 (nodejs 알고리즘 풀이)
Algorithm/Beakjoon 2022. 8. 11. 21:19

문제의 저작권은 백준 알고리즘(https://www.acmicpc.net/)에 있습니다 문제 풀이 중복 제거를 위해 집합의 성질을 활용하면 쉽게 풀 수 있다. const solution = (input) => new Set(input.map((s) => +s % 42)).size; const input = []; require('readline') .createInterface({ input: process.stdin }) .on('line', (line) => input.push(line)) .on('close', (_) => { console.log(solution(input)); process.exit(0); }); 전체 코드 https://github.com/bluemiv/Algorithm/blo..