Skip to content

week5 nkim #27

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
10 changes: 10 additions & 0 deletions nkim/week5/K번째수.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function solution(array, commands) {
var answer = [];

commands.forEach(([i, j, k]) => {
const slice_arr = array.slice(i - 1, j);
slice_arr.sort((a, b) => a - b);
answer.push(slice_arr[k - 1]);
});
return answer;
}
25 changes: 25 additions & 0 deletions nkim/week5/모의고사.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
function solution(answers) {
var answer = [];

const answer_cnt = [0, 0, 0];
const pattern1 = [1, 2, 3, 4, 5]; //5
const pattern2 = [2, 1, 2, 3, 2, 4, 2, 5]; //8
const pattern3 = [3, 3, 1, 1, 2, 2, 4, 4, 5, 5]; //10

answers.forEach((answer, idx) => {
if (pattern1[idx % pattern1.length] === answer) answer_cnt[0] += 1;
if (pattern2[idx % pattern2.length] === answer) answer_cnt[1] += 1;
if (pattern3[idx % pattern3.length] === answer) answer_cnt[2] += 1;
});

const max = Math.max(...answer_cnt);
let idx = answer_cnt.indexOf(max);
let i;
while (idx != -1) {
answer.push(idx + 1);
i = idx + 1;
idx = answer_cnt.indexOf(max, i);
}

return answer;
}
28 changes: 28 additions & 0 deletions nkim/week5/신고 결과 받기.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
function solution(id_list, report, k) {
var answer = {};
const repoCount = {};
const repoSet = {};
const repoFilter = new Set();
const stopId = new Set();

id_list.forEach((id) => {
answer[id] = 0;
repoCount[id] = 0;
repoSet[id] = [];
});
report.forEach((data) => repoFilter.add(data));
repoFilter.forEach((repo) => {
const [user_id, report_id] = repo.split(" ");
repoCount[report_id] += 1;
if (repoCount[report_id] >= k) stopId.add(report_id);
repoSet[user_id].push(report_id);
});
Object.entries(repoSet).forEach(([user_id, report_id_list]) => {
stopId.forEach((stop_id) => {
if (report_id_list.includes(stop_id)) answer[user_id] += 1;
});
});
answer = Object.values(answer);

return answer;
}