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
21 changes: 21 additions & 0 deletions nkim/week6/์‹คํŒจ์œจ.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
function solution(N, stages) {
var answer = [];
const report = {};
[...new Array(N)].forEach((_, i) => {
report[i + 1] = { stop: 0, dare: 0, fail_rate: 0 };
});

Object.keys(report).forEach((stage) => {
report[stage].stop = stages.filter((s) => s == stage).length;
report[stage].dare = stages.filter((s) => s >= stage).length;
});
Object.entries(report).forEach(([stage, val]) => {
const { stop, dare } = val;
report[stage].fail_rate = stop / dare;
});
answer = Object.keys(report).sort(
(i, j) => report[j].fail_rate - report[i].fail_rate
);
answer = answer.map((data) => parseInt(data));
return answer;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
function solution(numbers) {
var answer = 0;
const numObj = {};

[...new Array(10)].forEach((_, i) => {
numObj[i] = 0;
});
numbers.forEach((num) => {
numObj[num]++;
});
Object.entries(numObj).forEach(([num, cnt]) => {
if (!cnt) answer += parseInt(num);
});

return answer;
}
34 changes: 34 additions & 0 deletions nkim/week6/์ฒด์œก๋ณต.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
function solution(n, lost, reserve) {
var answer = n - lost.length;
const lost_arr = lost.sort((a, b) => a - b);
const re_arr = reserve
.filter((re, i) => {
const idx = lost_arr.indexOf(re);
const flag = idx != -1;
if (flag) {
lost_arr.splice(idx, 1);
answer++;
}
return !flag;
})
.sort((a, b) => a - b);

re_arr.forEach((re, i) => {
let idx;
idx = lost_arr.indexOf(re - 1);
console.log(idx);
if (idx != -1) {
lost_arr.splice(idx, 1);
answer++;
return false;
}
idx = lost_arr.indexOf(re + 1);
if (idx != -1) {
lost_arr.splice(idx, 1);
answer++;
return false;
}
});

return answer;
}