Skip to content
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
34 changes: 34 additions & 0 deletions problems/모의고사/solution.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
function solution(answers) {
let answer = [];

let score = [ 0, 0, 0]
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]
Comment on lines +2 to +7
Copy link
Contributor

@Happhee Happhee Jun 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요런 배열은 const로 선언하는게 조아여!!! 안전하게~.~

그른데 이제 제안할수 있는거느은 supo1,supo2, supo3보다는 supo로 하나의 배열 사용해서 이차원 쓸수도 있다아~.~



for (var i = 0; i < answers.length; i++){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var는 지양해주세여!! let 고고!!

if (supo1[i] === answers[i]) score[0]++
if (supo2[i] === answers[i]) score[1]++
if (supo3[i] === answers[i]) score[2]++

if (i > supo1.length-1) {
if(supo1[i%supo1.length] === answers[i]) score[0]++
}
if (i > supo2.length-1) {
if(supo2[i%supo2.length] === answers[i]) score[1]++
}
if (i > supo3.length-1) {
if(supo3[i%supo3.length] === answers[i]) score[2]++
}
Comment on lines +11 to +23
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그렇게 되면 요기 코드 반복되는 부분들을 줄일 수도 있겟져?!

}

let max_score = Math.max(...score)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

변수이름은 !! lowerCamelCase 로!
maxScore

요기서는 값이 변하지 않으니까 const로 쓰면 데게쮸?!

let fromIndex = score.indexOf(max_score);
while(fromIndex != -1) {
answer.push(fromIndex+1);
fromIndex = score.indexOf(max_score, fromIndex+1);
}

return answer;
}
47 changes: 47 additions & 0 deletions problems/모의고사/주희/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
https://programmers.co.kr/learn/courses/30/lessons/42840?language=javascript

//문제의 수 모름, 정답 모름.. 얘가 맞는지 아닌지 확인하려면 문제 수만큼 각 수포자의 정답을 한번씩 돌아봐야..겠지..?
//1번 수포자는 1,2,3,4,5 순서
//2번 수포자는 2,1 2,3 2,4 2,5 순서
//3번 수포자는 3 2번, 1 2번, 2 2번, 4 2번, 5 2번 순서
//수포자들 정답이 나름 규칙을 가지고 있다면.. 규칙에 맞게 반복해서 정답과 비교해보면 되지 않을까?

function solution(answers) { //받아오라 문제 정답!
let answer = []; //뱉어내라 누가 젤 많이 맞췄냐!

let score = [ 0, 0, 0] //각 수포자의 점수를 가지고 있을 배열
let supo1 = [1,2,3,4,5] //수포자 1번 정답 규칙 아래는 수포자2, 수포자3꺼
let supo2 = [2,1,2,3,2,4,2,5]
let supo3 = [3,3,1,1,2,2,4,4,5,5]


//문제의 수만큼 즉, 정답 배열의 길이만큼 이거를 반복해라잉?
for (var i = 0; i < answers.length; i++){
if (supo1[i] === answers[i]) score[0]++
if (supo2[i] === answers[i]) score[1]++
if (supo3[i] === answers[i]) score[2]++
// 여기까지 했는데 오류가 남.. 왜지? 왤까?
// 문제 길이가 수포자들이 가지고 있는 정답규칙 배열 길이보다 길면 채점을 못해줬음..
// 위에와 같은 상황일 때 다시 인덱스를 반복시켜주셈!!
if (i > supo1.length-1) {
if(supo1[i%supo1.length] === answers[i]) score[0]++
}
if (i > supo2.length-1) {
if(supo2[i%supo2.length] === answers[i]) score[1]++
}
if (i > supo3.length-1) {
if(supo3[i%supo3.length] === answers[i]) score[2]++
}
}

let max_score = Math.max(...score) //전개연산자를 넣어라.. 이유가 뭘까..?
// 특정 값이 있는 모든 위치(index)찾는 반복문!
let fromIndex = score.indexOf(max_score); //가장 높은 점수를 가진 첫번째 인덱스
while(fromIndex != -1) {
answer.push(fromIndex+1);
fromIndex = score.indexOf(max_score, fromIndex+1); //가장 높은 점수를 가진 값을 찾는데, 앞에서 나온 인덱스보다 뒤에서 찾아!
// 이제 더 이상 가장 높은 점수를 가진 인덱스가 없어! 그럼 -1을 우엑!하고 반복문 마무리.
}

return answer;
}