function solution(m, musicinfos) {
// let ans = [0, ''];
// const changeMSet = new Set(m.match(/[A-Z]#/g));
// changeMSet.forEach(word => {
// const regex = new RegExp(`${word}`, 'g');
// m = m.replace(regex, word[0].toLowerCase());
// })
m = m.replace(/[A-Z]#/g, w => w[0].toLowerCase());
// sort가 아주 조~~~~금 느림
// musicinfos.sort((a, b) => {
// const [aStart, aEnd] = a.split(','), [bStart, bEnd] = b.split(',');
// const aTime = (new Date(`2023 ${aEnd}`) - new Date(`2023 ${aStart}`)) / 60000;
// const bTime = (new Date(`2023 ${bEnd}`) - new Date(`2023 ${bStart}`)) / 60000;
// return bTime - aTime;
// })
for(let info of musicinfos) {
let [start, end, title, melody] = info.split(',');
const playTime = (new Date(`2023 ${end}`) - new Date(`2023 ${start}`)) / 60000;
// const changeSet = new Set(melody.match(/[A-Z]#/g))
// changeSet.forEach(word => {
// const regex = new RegExp(`${word}`, 'g');
// melody = melody.replace(regex, word[0].toLowerCase());
// })
melody = melody.replace(/[A-Z]#/g, w => w[0].toLowerCase());
const len = melody.length;
if(playTime < melody.length) melody = melody.slice(0, playTime);
else if(playTime > melody.length) melody = melody.repeat(Math.floor(playTime/len)) + melody.slice(0, playTime%len);
// if(melody.indexOf(m)+1) return title; // sort 전용
if(melody.indexOf(m)+1 && ans[0] < playTime) ans = [playTime, title]
}
return ans[0] ? ans[1] : '(None)';
}
reduce(/regex/g, m => m[0])
new Date('03:00') // invalid
new Data('2023 03:00') // 2023년 1/1 3시
new Date('3/23') // 현재 해 3/23 0시