문제출처
function solution(s) {
const answer = [];
const str = s.substring(1, s.length - 1);
let arr = [];
let nowArr = [];
let now = '';
for (let i=0; i<str.length; i++) {
if (str[i] === '{') continue;
else if (str[i] === '}') {
nowArr.push(+now);
arr.push(nowArr);
nowArr = [];
now = '';
}
else if (str[i] === ',') {
if (str[i-1] === '}') continue;
nowArr.push(+now);
now = '';
} else {
now += str[i];
}
}
arr = arr.sort((a,b) => a.length - b.length)
for (const a of arr) {
const tmp = a.filter(v => !answer.includes(v))[0];
answer.push(tmp)
}
return answer;
}