1 回答

TA貢獻1844條經驗 獲得超8個贊
這可能就是您正在尋找的:
function padHours(str) {
const [minutes, seconds] = str.match(/\d{1,2}/g);
return (minutes.length < 2 ? '0' + minutes : minutes) + ':' + seconds;
}
const a = new Set(['07:00', '08:00', '09:00', '10:00', '11:00', '12:00', '13:00', '14:00', '15:00', '16:00', '17:00', '18:00'].map(padHours));
const b = new Set(['07:00', '8:00', '9:00', '15:00', '16:00', '17:00', '11:00', '12:00', '13:00'].map(padHours));
// Converting to an array allows to filter (which is not possible on Sets)
const arr = [...a, ...b].filter(x => !a.has(x) || !b.has(x));
console.log(arr);
// And if you absolutely want the result as a Set
const result = new Set(arr);
console.log(result);
添加回答
舉報