
const fs = require('fs');
const path = process.platform === 'linux' ? '/dev/stdin' : 'input.txt';
const [a, b] = fs
.readFileSync(path)
.toString()
.trim()
.split(' ')
.map((it) => it.split('').reverse().join(''));
console.log(a > b ? a : b);
⏰ 소요한 시간 : -
자바스크립트에서는 문자열을 뒤집어주는 메서드가 없다.
따라서 split 메서드를 사용해 문자열을 배열로 변경한 후, 배열을 뒤집어준다. 그 후 join 연산자를 사용해 다시 배열을 문자열로 바꿔준다.
참고로 let을 사용해서 빈 문자열을 만들고 for문을 돌면서 빈 문자열에 더해주는 방식이 훨씬 빠르다.