개발로그필름
[프로그래머스] 주사위의 개수 javascript 본문
728x90
반응형
SMALL
https://school.programmers.co.kr/learn/courses/30/lessons/120845
문제
나의 풀이
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
'coding test > 프로그래머스' 카테고리의 다른 글
[프로그래머스] 숨어있는 숫자의 덧셈(1) javascript (1) | 2023.05.19 |
---|---|
[프로그래머스] 문자열 정렬하기(1) javascript (0) | 2023.05.18 |
[프로그래머스] 배열 회전시키기 javascript (pop, shift, splice, filter, delete) (0) | 2023.04.27 |
[프로그래머스] 공 던지기 javascript (0) | 2023.04.26 |
[프로그래머스] 2차원으로 만들기 javascript (0) | 2023.04.25 |
Comments