Skip to content

Commit

Permalink
09.04: string(대소문자 바꾸기)
Browse files Browse the repository at this point in the history
  • Loading branch information
luckylooky2 committed Sep 4, 2024
1 parent 09c15a9 commit 36dfb2d
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions baekjoon/2744.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 대소문자 바꾸기 : 구현, 문자열
const buffer = require("fs").readFileSync(0);

console.log(
buffer
.map((c) => (c < 91 ? c + 32 : c - 32))
.toString()
.slice(0, -1)
);

// 1. require("fs").readFileSync(0);
// - input: 123, output: <Buffer 31 32 33 0a>
// 2. "utf-8" encoding을 하면 문자열로 변환됨. 즉, toString() 메서드를 사용할 필요가 없어짐
// 3. trim이 필요한 이유는 마지막의 개행이 있을 수도 있기 때문
// 4. "utf-8" 이나 toString을 하지 않으면, 위처럼 ascii code로 처리가 가능

0 comments on commit 36dfb2d

Please sign in to comment.