[프로그래머스] 더 크게 합치기

·2023년 5월 10일
0

프로그래머스_0단계

목록 보기
48/49

연산 ⊕는 두 정수에 대한 연산으로 두 정수를 붙여서 쓴 값을 반환합니다. 예를 들면 다음과 같습니다.

12 ⊕ 3 = 123
3 ⊕ 12 = 312
양의 정수 a와 b가 주어졌을 때, a ⊕ b와 b ⊕ a 중 더 큰 값을 return 하는 solution 함수를 완성해 주세요.
단, a ⊕ b와 b ⊕ a가 같다면 a ⊕ b를 return 합니다.

내 풀이

function solution(a, b) {
    return parseInt(a.toString() + b.toString()) > parseInt(b.toString() + a.toString()) ? parseInt(a.toString() + b.toString()) : parseInt(b.toString() + a.toString())
}

다른 사람의 풀이

function solution(a, b) {
    return Math.max(Number(`${a}${b}`), Number(`${b}${a}`))
}
profile
개발자가 되는 과정

0개의 댓글