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]) +} + 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 +} 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