From 2ce382b076df79c0a85b9b354ccdadee8994d712 Mon Sep 17 00:00:00 2001 From: Ryujeuk Date: Mon, 27 May 2019 14:58:40 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20H=20index,=20=EB=AA=A8=EC=9D=98?= =?UTF-8?q?=EA=B3=A0=EC=82=AC=20=ED=92=80=EC=9D=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 190524/circus/hIndex.js | 34 ++++++++++++++++++++++++++++++++++ 190527/circus/exam.js | 19 +++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 190524/circus/hIndex.js create mode 100644 190527/circus/exam.js diff --git a/190524/circus/hIndex.js b/190524/circus/hIndex.js new file mode 100644 index 0000000..d507e9f --- /dev/null +++ b/190524/circus/hIndex.js @@ -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; + } + } +} \ No newline at end of file diff --git a/190527/circus/exam.js b/190527/circus/exam.js new file mode 100644 index 0000000..a5cac56 --- /dev/null +++ b/190527/circus/exam.js @@ -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; +} \ No newline at end of file