[프로그래머스] Level 0 가장 큰 수 찾기 javascript

G E Lee·2023년 1월 2일
0

코딩테스트

목록 보기
8/13
post-thumbnail

Level 0 가장 큰 수 찾기

문제 링크 :
https://school.programmers.co.kr/learn/courses/30/lessons/120899

풀이 방법

max() 메서드로 array에서 가장 큰 수를 찾는다.
숫자는 중복이 없으므로 array에서 제일 큰 수의 index를 찾는다.

풀이 코드

function solution(array) {
    const max = Math.max(...array);
    const answer = [max, array.indexOf(max)]
    return answer
}
profile
배움은 끝이 없다

0개의 댓글

Powered by GraphCDN, the GraphQL CDN