개발로그필름

[프로그래머스] 주사위의 개수 javascript 본문

coding test/프로그래머스

[프로그래머스] 주사위의 개수 javascript

yuullog 2023. 5. 17. 13:08
728x90
반응형
SMALL

 

https://school.programmers.co.kr/learn/courses/30/lessons/120845

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

문제

 

나의 풀이

function solution(box, n) {
    let width = Math.floor(box[0] / n);
    let length = Math.floor(box[1] / n);
    let height = Math.floor(box[2] / n);
    let answer = width * length * height;
    return answer;
}

 

다른 사람 풀이

function solution(box, n) {
    let [width, length, height] = box;

    return Math.floor(width / n) * Math.floor(length / n) * Math.floor(height / n);

}

나와 비슷한 방법으로 풀었는데 코드가 훨씬 깔끔하고 보기 좋다.

각각의 변수를 일일히 만드는 것이 아닌

box가 배열 타입이기 때문에 [width, length, height] = box; 이런식으로 각 인덱스에 맞춰 변수를 할당해준다

 

 

반응형
LIST
Comments