Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[개발자 비상근무] 리나 미션 제출합니다. #20

Open
wants to merge 6 commits into
base: leena-main
Choose a base branch
from

Conversation

1jeongg
Copy link
Collaborator

@1jeongg 1jeongg commented Mar 12, 2024

허허.. 이번엔 늦었네요 ㅠㅠ

구현 방식을 어떻게 할 지 고민하다가 잘못될 경우마다 스택에 넣을까? 하다가 너무 복잡할 것 같아서 미리 근무자 리스트를 만들고 코틀린 내장 메서드를 최대한 활용해서 구현했습니다! 테스트 코드를 짜긴 했는데.. 이 방식이 맞는지 사실 확신은 못하겠네요ㅠㅠ

저는 평일 근무자와 휴일 근무자를 전체 날짜만큼 순서대로 만들어두고 전체 근무자 리스트의 마지막 사람과 이름이 다른 가장 앞에있는 근무자 를 전체 근무자 리스트에 추가하고 평일/휴일 근무자 리스트에서 해당 근무자를 삭제하는 방법을 사용했어요!

private val holidayWorker = MutableList(endDate) { i -> oncallInformationDTO.holidayWorkerList[i%size] }
private val weekdayWorker = MutableList(endDate) { i -> oncallInformationDTO.weekdayWorkerList[i%size] }

fun getWorkerList(): List<String> {
    val workerList = mutableListOf<String>()
    for (date in 1..endDate) {
        val workers = getWorkerList(date)
        val workerIndex = workers.indexOfFirst { workerList.isEmpty() || it != workerList.last() }
        workerList.add(workers[workerIndex])
        workers.removeAt(workerIndex)
    }
    return workerList.toList()
}
private fun getWorkerList(date: Int) = if (isHoliday(date)) holidayWorker else weekdayWorker

@1jeongg 1jeongg self-assigned this Mar 12, 2024
@1jeongg 1jeongg requested review from gusah009 and stopmin March 12, 2024 02:07
Copy link
Collaborator

@gusah009 gusah009 left a comment

Choose a reason for hiding this comment

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

테스트도 꼼꼼하게 짜여져있고 구현하기 어려웠을 과제인데 로직을 깔끔하게 구현한 것 같습니다~ 수고하셨습니다~ 👍👍

try {
return inputFunction()
} catch (_: IllegalArgumentException) {
outputManager.printExceptionMessage()
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍👍

Comment on lines +55 to +61
fun getEndDateOfMonth(month: Int): Int {
if (month !in 1..12) {
throw IllegalArgumentException()
}
val daysOfMonth = listOf(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
return daysOfMonth[month-1]
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Month가 1~12 안에 속하는지 input 클래스와 여기 두 곳에서 검증하는 것 같은데, Month data 클래스를 만들어서 가지고 옮겨다니면 내부적으로 daysOfMonth도 가질 수 있어서 코드가 더 깔끔해 질 것 같아요~

enum class Holiday(
val month: Int,
val date: Int,
val korean: String
Copy link
Collaborator

Choose a reason for hiding this comment

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

korean 좋네요 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants