From c21ea317464a371b8bf69adcb4ac1c5705dd58be Mon Sep 17 00:00:00 2001 From: Hoyoung Jung Date: Mon, 20 May 2019 16:52:03 +0900 Subject: [PATCH 1/4] Add 190521 problem MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 프로그래머스 k번째수 --- 190521/problem.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 190521/problem.md diff --git a/190521/problem.md b/190521/problem.md new file mode 100644 index 0000000..d026760 --- /dev/null +++ b/190521/problem.md @@ -0,0 +1,6 @@ +# K번째 수 + +- https://programmers.co.kr/learn/courses/30/lessons/42748 +- 분류: 정렬 +- 난이도: 1점 + From ee669467578bfa40a74221605f30749b90c4c353 Mon Sep 17 00:00:00 2001 From: Yongsu Jeong Date: Tue, 21 May 2019 14:20:34 +0900 Subject: [PATCH 2/4] =?UTF-8?q?k=EB=B2=88=EC=A7=B8=20=EC=88=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 190521/kthnumber.js | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 190521/kthnumber.js diff --git a/190521/kthnumber.js b/190521/kthnumber.js new file mode 100644 index 0000000..dbb0612 --- /dev/null +++ b/190521/kthnumber.js @@ -0,0 +1,4 @@ +function solution(array, commands) { + return commands.map(([from, to, index]) => array.slice(from - 1, to).sort((x,y) => (x - y).slice())[index - 1]) +} + From 393de04370c7d142a76f6ba4447e90893fa5c3b3 Mon Sep 17 00:00:00 2001 From: su Date: Fri, 24 May 2019 17:03:39 +0900 Subject: [PATCH 3/4] =?UTF-8?q?h=EB=B2=88=EC=A7=B8=20=EC=9D=B8=EB=8D=B1?= =?UTF-8?q?=EC=8A=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 195024/test.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 195024/test.js diff --git a/195024/test.js b/195024/test.js new file mode 100644 index 0000000..3a3890c --- /dev/null +++ b/195024/test.js @@ -0,0 +1,44 @@ +// Version 1 +function solution(citations) { + let array = new Array(citations.length).fill(0); + let sortedArr = citations.sort((a, b) => b - a); + let answer; + + for(let i = 0; i < citations.length; i++) { + for(let j = 0; j < citations.length; j++) { + if(sortedArr[j] <= sortedArr[i]) { + array[(citations.length - 1) - i]++; + } + } + } + + sortedArr.some((val) => { + if(array[sortedArr.indexOf(val)] >= val) { + answer = val; + return true; + } + }) + + return answer +} + +// Version 2 +function solution(citation) { +let array = []; +let sortedArr = citation.sort((a, b) => a - b); +let answer; + +for(let i = citation.length; i > 0; i--) { + array.push(i); +} + +sortedArr.some((val, index) => { + + if(val >= array[index]) { + answer = array[index]; + return true; + } +}) + +return answer === undefined ? 0 : answer; +} \ No newline at end of file From 32e9bbffb600f349ebbc7c571d35a11660cad40b Mon Sep 17 00:00:00 2001 From: su Date: Mon, 27 May 2019 14:41:08 +0900 Subject: [PATCH 4/4] mockExam algorithm --- 190527/mockExam.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 190527/mockExam.js diff --git a/190527/mockExam.js b/190527/mockExam.js new file mode 100644 index 0000000..9f3ea56 --- /dev/null +++ b/190527/mockExam.js @@ -0,0 +1,21 @@ +function solution(answers) { + let answer = []; + let supo1 = [1,2,3,4,5]; + let supo2 = [2,1,2,3,2,4,2,5]; + let supo3 = [3,3,1,1,2,2,4,4,5,5]; + let ans1 = howManyCorrect(answers , supo1); + let ans2 = howManyCorrect(answers , supo2); + let ans3 = howManyCorrect(answers , supo3); + let max = Math.max(ans1,ans2,ans3); + if( max === ans1) answer.push(1); + if( max === ans2) answer.push(2); + if( max === ans3) answer.push(3); + + return answer; +} + +function howManyCorrect(ans , supo) { + return ans.filter(function(v, i){ + return v === supo[i % supo.length]; + }).length +}