무조건 map을 써야지!!!
function solution(age) {
let arr=['a','b','c','d','e','f','g','h','i','j'];
return age.toString().split('').map(e=>arr[e]).join('');
}
toString()은 문자열을 반환하는 object의 대표적인 방법.
모든 객체에는 객체가 문자열로 표시/참조될 때 자동으로 호출되는 toString()메서드를 갖고 있다.
String 전역객체로, 문자열의 생성자이다.
var s1='2+2';
var s2=new String('2+2');
console.log(eval(s1)); //4
console.log(eval(s2)); //'2+2'
const stringObj = new String('foo');
console.log(stringObj);
// String { "foo" }
console.log(stringObj.toString());
//"foo"
다른 사람의 풀이를 봤는데,
function solution(age) {
return age
.toString()
.split("")
.map((v) => "abcdefghij"[v])
.join("");
}
문자열 자체도 인덱스로 접근 가능하므로 "abcdefghij"[v] 이렇게 써준 게 인상 깊었다.