function solution(p) {
let num = [];
let x = p.split('+').map((e) => {
if (e.includes('x')) {
return e.trim().charAt(0) == 'x' ? 1 : Number(e.split('x')[0].trim());
} else {
num.push(Number(e));
return 0;
}
});
let xnum = 0;
let nnum = 0;
x.forEach(e => xnum+=e);
num.forEach(e => nnum+=e);
return nnum == 0 ? `${xnum}x` : `${xnum}x + ${nnum}`;
}
https://school.programmers.co.kr/learn/courses/30/lessons/120863
해결되면 따로 정리해서 올릴 예정이다!