Skip to content
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

[2022.04.23] 프로그래머스 풀이 추가 #40

Merged
merged 4 commits into from
Apr 25, 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
15 changes: 15 additions & 0 deletions level-1/K번째수.js
Original file line number Diff line number Diff line change
@@ -45,3 +45,18 @@ function solution(array, commands) {
}
return answer;
}

// 정답 5 - chaerin-dev
function solution(array, commands) {
let t = commands.length;
let answer = [];
while (t--) {
Copy link
Owner

Choose a reason for hiding this comment

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

while 문의 조건을 이렇게 표현하는 방식도 있겠네요!! 그런데 for 문 대신 이렇게 표현하신 이유가 있으신지 궁금합니다!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@codeisneverodd 테스트케이스가 t개인 문제를 이런식으로 푸는 게 습관이 되어 있어서요!! 이 문제도 어떻게 보면 테스트케이스가 여러 개인 문제라고 볼 수 있어서 습관적으로 이렇게 코드를 작성했습니다.

let command = commands.shift();
answer.push(
array.slice(command[0] - 1, command[1]).sort((a, b) => a - b)[
command[2] - 1
]
);
}
return answer;
}
13 changes: 13 additions & 0 deletions level-1/로또의-최고-순위와-최저-순위.js
Original file line number Diff line number Diff line change
@@ -137,3 +137,16 @@ function solution(lottos, win_nums) {

return [max, min]
}

//정답 7 - chaerin-dev
function solution(lottos, win_nums) {
let zeroCount = 0;
let winCount = 0;
lottos.forEach((item) => {
if (item === 0) zeroCount++;
else if (win_nums.includes(item)) winCount++;
});
let maxRank = Math.min(7 - (winCount + zeroCount), 6);
let minRank = Math.min(7 - winCount, 6);
return [maxRank, minRank];
}
9 changes: 9 additions & 0 deletions level-1/부족한-금액-계산하기.js
Original file line number Diff line number Diff line change
@@ -46,4 +46,13 @@ function solution(price, money, count) {
}

return sum < money ? 0 : sum - money;
}

//정답 4 - chaerin-dev
function solution(price, money, count) {
let totalPrice = 0;
for(let i=1; i<=count; i++){
totalPrice += i * price;
}
return money > totalPrice ? 0 : totalPrice-money;
}