Skip to content

[2022.03.31] 4문제 - 솔루션 추가 #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 31, 2022
Merged
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: 17 additions & 1 deletion level-1/2016년.js
Original file line number Diff line number Diff line change
@@ -11,4 +11,20 @@ function solution(a, b) {
answer = day[(count + 4) % 7]

return answer;
}
}

//정답 2 - yongchanson
function solution(a, b) {
const month = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
const week = ["THU", "FRI", "SAT", "SUN", "MON", "TUE", "WED"];

let sum = b;
for (
let i = 0;
i < a - 1;
i++ //ex)5월인 경우 1~4월까지 더해준다.
)
sum += month[i];

return week[sum % 7]; //1일이 금요일이므로, 0이면 목요일이 출력되어야 한다.
}
13 changes: 12 additions & 1 deletion level-1/가운데-글자-가져오기.js
Original file line number Diff line number Diff line change
@@ -6,4 +6,15 @@ function solution(s) {
const length = s.length
answer = (length % 2) !== 0 ? s[Math.floor(length / 2)] : s.slice((length / 2) - 1, (length / 2) + 1)
return answer;
}
}

//정답 2 - yongchanson
function solution(s) {
var answer = "";
let L2 = s.length / 2;
Copy link
Owner

Choose a reason for hiding this comment

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

저도 s.length/2 가 많이 반복되는데 용찬님 처럼 변수로 선언할 것 그랬네요! 보고 배워갑니다 😄


answer =
s.length % 2 == 0 ? s[L2 - 1] + s[L2] : (answer = s[Math.ceil(L2 - 1)]);

return answer;
}
12 changes: 11 additions & 1 deletion level-1/내적.js
Original file line number Diff line number Diff line change
@@ -5,4 +5,14 @@ function solution(a, b) {
var answer = 1234567890;
answer = a.reduce((x, y, i) => x + y * b[i], 0)
return answer;
}
}

//정답 2 - yongchanson
function solution(a, b) {
var answer = 0;

for(i=0; i<a.length; i++) {
answer += a[i] * b[i]
}
return answer;
}
19 changes: 18 additions & 1 deletion level-1/부족한-금액-계산하기.js
Original file line number Diff line number Diff line change
@@ -7,4 +7,21 @@ function solution(price, money, count) {
for (let i = 1; i <= count; i++) totalCost += price * i
answer = totalCost <= money ? 0 : totalCost - money
return answer;
}
}

//정답 2 - yongchanson
function solution(price, money, count) {
var answer = 0;
let sum = price;

for (i = 2; i <= count; i++) {
sum += price * i;
}

if (sum <= money) {
answer = 0;
} else {
answer = sum - money;
}
return answer;
}