✨ 문제 ✨

✨ 정답 ✨
function replaceSharp(str) {
str = str.replace(/C#/gi, "Z");
str = str.replace(/D#/gi, "X");
str = str.replace(/F#/gi, "V");
str = str.replace(/G#/gi, "N");
str = str.replace(/A#/gi, "M");
return str;
}
function solution(m, musicinfos) {
let answer=[];
m=replaceSharp(m)
for (let i=0;i<musicinfos.length;i++){
let [musicStart, musicEnd, title, cords]=musicinfos[i].split(',');
cords=replaceSharp(cords);
let endHour=parseInt(musicEnd.split(':')[0])
let endMin=parseInt(musicEnd.split(':')[1])
let startHour=parseInt(musicStart.split(':')[0]);
let startMin=parseInt(musicStart.split(':')[1]);
let songTime=endHour*60+endMin-startHour*60-startMin;
if (songTime<cords.length){
cords=cords.slice(0,songTime)
}else if (songTime>cords.length){
let calculate=parseInt(songTime/cords.length);
for (let j=0;j<calculate;j++){
if (cords.length>songTime){
break;
}
cords+=cords;
}
cords=cords.slice(0, songTime);
}
if (cords.includes(m)){
answer.push([title, songTime]);
};
}
if (answer.length===0){
return "(None)";
}
if (answer.length>1){
answer.sort((a,b)=>{
if (a[1]>b[1]){
return -1;
}
if (a[1]===b[1]){
return 0;
}
if (a[1]<b[1]){
return 1;
}
})
console.log(answer)
return answer[0][0];
}
console.log(answer)
return answer[0][0];
}
🧵 참고한 정답지 🧵
https://velog.io/@highero-k/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4-%EB%B0%A9%EA%B8%88%EA%B7%B8%EA%B3%A1-JavaScript-Level-2
💡💡 기억해야 할 점 💡💡