๋ฐ์ํ
Problem Description.
์ฐ์ฃผ์ฌํ์ ํ๋ ๋จธ์ฑ์ด๋ ์์ง ๊ณ ์ฅ์ผ๋ก PROGRAMMERS-962 ํ์ฑ์ ๋ถ์์ฐฉํ๊ฒ ๋์ต๋๋ค. ์ ๊ตญ์ฌ์ฌ์์ ๋์ด๋ฅผ ๋งํด์ผ ํ๋๋ฐ, PROGRAMMERS-962 ํ์ฑ์์๋ ๋์ด๋ฅผ ์ํ๋ฒณ์ผ๋ก ๋งํ๊ณ ์์ต๋๋ค. a๋ 0, b๋ 1, c๋ 2, ..., j๋ 9์ ๋๋ค. ์๋ฅผ ๋ค์ด 23์ด์ cd, 51์ด์ fb๋ก ํํํฉ๋๋ค. ๋์ด age๊ฐ ๋งค๊ฐ๋ณ์๋ก ์ฃผ์ด์ง ๋ PROGRAMMER-962์ ๋์ด๋ฅผ returnํ๋๋ก solution ํจ์๋ฅผ ์์ฑํด์ฃผ์ธ์.
Restrictions.
- age๋ ์์ฐ์์ ๋๋ค.
- age ≤ 1,000
- PROGRAMMERS-962 ํ์ฑ์ ์ํ๋ฒณ ์๋ฌธ์๋ง ์ฌ์ฉํฉ๋๋ค.
Input/Output Example.
age result
23 "cd"
51 "fb"
100 "baa"
My solution
function solution(age) {
const alphabet = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
const ageArray = age.toString().split('');
const numbers = ageArray.map(Number)
return numbers.map((x) => alphabet[x]).join("");
}
Another solution
function solution(age) {
return age
.toString()
.split("")
.map((v) => "abcdefghij"[v])
.join("");
}
๋ฌธ์์ด ์์ฒด๋ ์ธ๋ฑ์ค[] ์ ๊ทผํ๋ค๋ ์ ๊ธฐ์ตํ๊ธฐ
https://school.programmers.co.kr/learn/courses/30/lessons/120834
๋ฐ์ํ
'Problem Solution > Programmers' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ๋ก๊ทธ๋๋จธ์ค/JS] ์ ์ ์์น ๊ตฌํ๊ธฐ (0) | 2023.10.17 |
---|---|
[ํ๋ก๊ทธ๋๋จธ์ค/JS] ์ค์๊ฐ ๊ตฌํ๊ธฐ (1) | 2023.10.17 |
[ํ๋ก๊ทธ๋๋จธ์ค/JS] ๋ฌธ์์ด ์ ๋ ฌํ๊ธฐ (1) (0) | 2023.09.26 |
[ํ๋ก๊ทธ๋๋จธ์ค/JS] ๊ฐ์ฅ ํฐ ์ ์ฐพ๊ธฐ (0) | 2023.09.25 |
[ํ๋ก๊ทธ๋๋จธ์ค/JS] ์ต๋๊ฐ ๋ง๋ค๊ธฐ (2) (0) | 2023.09.22 |