0레벨. 문제:https://school.programmers.co.kr/learn/courses/30/lessons/120818
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
//다른 사람 풀이
const discounts = [
[500000, 20],
[300000, 10],
[100000, 5],
]
const solution = (price) => {
for (const discount of discounts) //배열 순회 for of 문
if (price >= discount[0]) //50만원 이상 30만원이상 50만원미만 10만원이상 30만원미만
return Math.floor(price - price * discount[1] / 100) //중괄호안하면 if한줄만 영역
return price
}
//내가 푼 풀이
function solution(price) {
let finalPrice = 0;
if (price>=100000 &&price<300000){
finalPrice = price - price*0.05 ;
return Math.floor(finalPrice);
}else if(price>=300000 && price<500000){
finalPrice = price - price*0.1 ;
return Math.floor(finalPrice)
}else if(price>=500000) {
finalPrice = price - price*0.2 ;
return Math.floor(finalPrice)
}else if(price<100000){
return price;
}
}
이중 배열로 순회한다는 점이 가장 인상깊었고, Q. for of 문은 중괄호로 감싸지 않으면 어디까지가 for of문 블럭영역일까? .( if문은 {} 중괄호 생략시 한줄만 if 조건절에 해당된다.) Q.화살표함수는 내부에서 어떻게 작동하는 걸까,
화살표함수에 대해 더 알아보자.
1.화살표 함수
deep dive 167pg
474pg
화살표 함수는 기존의 함수보다 표현,내부 동작 전부 간략화된 함수입니다. 따라서 기존의 함수 선언문/표현식을 완전히 대체할 수 없습니다. 항상 익명함수로 정의되며
'codingTest' 카테고리의 다른 글
프로그래머스-모의고사 완전탐색 풀이 (0) | 2023.04.26 |
---|---|
코플릿 superIncreasing (0) | 2023.04.03 |
프로그래머스 풀이 삼각형의 완성조건 (1) (0) | 2023.04.01 |
2. 코플릿 replace() 정규식 (0) | 2023.03.24 |
1.프로그래머스-순서쌍 Number.inInteger() (0) | 2023.03.22 |