Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Code Flow
About Variables in this code
Functional Descriptions
1️⃣ 입력 단계
getCarname
와 경주를 시도할 횟수getTimes
두 함수를async
를 사용하여play
함수 외부에 선언해 주었다.play
함수 내에서 각각names
와times
변수에 비동기 함수의 리턴값을 할당해주었다.2️⃣ 경주 실행 단계
race
와max
를 초기화한다.race
배열을 초기화할 때에는fill()
메서드를 사용하였다.times
만큼 반복문을 동작시킨다.forEach
메서드를 통해 자동차 이름과 인덱스에 접근한다.3️⃣ 우승자 선정, 출력
filter
메서드를 사용해race
의 요솟값이max
보다 크거나 같은name
을 선별한다.name
이 여러 개 일 경우를 대비하여join()
메서드를 통해 출력 형식을 형성한다.References
커스텀 에러
타입 확인하기 : int