Skip to content
Merged
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
34 changes: 34 additions & 0 deletions 190524/circus/hIndex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// 첫번째
function solution(citations) {
var answer = 0;
while (true) {
if (citations.filter(x => { return x > answer }).length > answer) {
answer += 1;
continue;
}
break;
}
return Math.max.apply(null, citations) === 0 ? 0 : answer;
}

// 두번째

function solution(citations) {
citations.sort((a, b) => b - a).unshift(0);
for (var i = citations.length - 1; i >= 0; i--) {
if (citations[i] >= i) return i;
}
}

// 세번째

function solution(citations) {
citations = citations.sort((a, b) => a - b);
while (true) {
if (citations.findIndex(x => x < citations.length) !== -1) {
citations.shift();
} else {
return citations.length;
}
}
}
19 changes: 19 additions & 0 deletions 190527/circus/exam.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
function solution(answers) {
var num1 = [1, 2, 3, 4, 5];
var num2 = [2, 1, 2, 3, 2, 4, 2, 5];
var num3 = [3, 3, 1, 1, 2, 2, 4, 4, 5, 5];
var results = [0, 0, 0];
var winer = [];

answers.forEach((ans, i) => {
if (ans === num1[i % num1.length]) results[0] += 1;
if (ans === num2[i % num2.length]) results[1] += 1;
if (ans === num3[i % num3.length]) results[2] += 1;
})

var max = Math.max(...results);
results.forEach((result, i) => {
if (result === max) winer.push(i + 1);
})
return winer;
}