Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions sujin/level0/69. 직각삼각형 출력하기.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const readline = require("readline");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});

let input = [];

rl.on("line", function (line) {
input = line.split(" ");
}).on("close", function () {
const N = Number(input[0]);
let answer = "";
for (let i = 1; i <= N; i++) {
answer += "*";
console.log(answer);
}
});
3 changes: 3 additions & 0 deletions sujin/level0/70. 문자열 정렬하기(2).js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function solution(my_string) {
return my_string.toLowerCase().split("").sort().join("");
}
9 changes: 9 additions & 0 deletions sujin/level0/71. 접두사인지 확인하기.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function solution(my_string, is_prefix) {
const prefix = [];
let element = "";
for (let i of my_string) {
element += i;
prefix.push(element);
}
return prefix.includes(is_prefix) ? 1 : 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

includes()를 사용해주셨군용

}
3 changes: 3 additions & 0 deletions sujin/level0/72. 글자 이어붙여 문자열 만들기.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function solution(my_string, index_list) {
return index_list.map((item, idx) => my_string[item]).join("");
}
3 changes: 3 additions & 0 deletions sujin/level0/73, 문자열 곱하기.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function solution(my_string, k) {
return my_string.repeat(k);
}
5 changes: 5 additions & 0 deletions sujin/level0/74. 원소들의 곱과 합.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function solution(num_list) {
const plus = num_list.reduce((acc, cur) => acc + cur, 0) ** 2;
const multiple = num_list.reduce((acc, cur) => acc * cur);
Comment on lines +2 to +3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

확실히 reduce 를 쓰니까 좀 더 간단하게 작성할 수 있네요!

return multiple < plus ? 1 : 0;
Comment on lines +2 to +4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reduce 방식으로 푸니 훨씬 간결하네용~👍

}
9 changes: 9 additions & 0 deletions sujin/level1/12. 두 정수 사이의 합.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function solution(a, b) {
const NUM_ARR = [a, b].sort((a, b) => a - b);
let answer = NUM_ARR[0];
if (a === b) return a;
for (let i = NUM_ARR[0] + 1; i <= NUM_ARR[1]; ++i) {
answer += i;
}
return answer;
}
12 changes: 12 additions & 0 deletions sujin/level1/13. 문자열 내 p와 y의 개수.js
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 수진님 객체로 풀었네요~! 👍

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function solution(s) {
const lowerCase = s.toLowerCase();
const compare = { p: 0, y: 0 };
for (let i of lowerCase) {
if (i === "p") {
compare.p += 1;
} else if (i === "y") {
compare.y += 1;
}
}
return compare.p === compare.y;
}
7 changes: 7 additions & 0 deletions sujin/level1/14. 음양 더하기.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function solution(absolutes, signs) {
let answer = 0;
signs.forEach((item, idx) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forEach()는 사용법을 알았다가도 자주 사용하지 않으니 까먹네요..ㅎㅎ
이렇게 쓸 수도 있군용

item ? (answer += absolutes[idx]) : (answer += -absolutes[idx]);
});
return answer;
}