-
[Programmers] JavaScript 알고리즘 | Lv.0 더 크게 합치기► JS Algorithm/Programmers 2023. 12. 14. 12:40반응형
🔒 문제 설명
연산 ⊕는 두 정수에 대한 연산으로 두 정수를 붙여서 쓴 값을 반환합니다. 예를 들면 다음과 같습니다.
- 12 ⊕ 3 = 123
- 3 ⊕ 12 = 312
양의 정수 a와 b가 주어졌을 때, a ⊕ b와 b ⊕ a 중 더 큰 값을 return 하는 solution 함수를 완성해 주세요.
단, a ⊕ b와 b ⊕ a가 같다면 a ⊕ b를 return 합니다.
🔒 제한사항
- 1 ≤ a, b < 10,000
🔒 입출력 예
a b result 9 91 991 89 8 898
🔒 입출력 예 설명
입출력 예 #1
- a ⊕ b = 991 이고, b ⊕ a = 919 입니다. 둘 중 더 큰 값은 991 이므로 991을 return 합니다.
입출력 예 #2
- a ⊕ b = 898 이고, b ⊕ a = 889 입니다. 둘 중 더 큰 값은 898 이므로 898을 return 합니다.
🔐 solution of mine
Number()
String()
const solution = (a, b) => console.log( Number(String(b) + String(a)) > Number(String(a) + String(b)) ? Number(String(b) + String(a)) : Number(String(a) + String(b)) ); solution(9, 91); // expected output: 991 solution(89, 8); // expected output: 898
🔐 solution of others
Math.max()
Number()
`${}`
const solution = (a, b) => console.log(Math.max(Number(`${a}` + `${b}`), Number(`${b}` + `${a}`))); solution(9, 91); // expected output: 991 solution(89, 8); // expected output: 898
반응형'► JS Algorithm > Programmers' 카테고리의 다른 글
[React Native_에러해결] xcode 에러해결 '►Start the active scheme' (0) 2023.12.15 [Programmers] JavaScript 알고리즘 | Lv.0 배열에서 문자열 대소문자 변환하기 (0) 2023.12.14 [Programmers] JavaScript 알고리즘 | Lv.0 공배수 (0) 2023.12.13 [Programmers] JavaScript 알고리즘 | Lv.0 조건에 맞게 수열 변환하기 1 (0) 2023.12.13 [Programmers] JavaScript 알고리즘 | Lv.0 5명씩 (0) 2023.12.13