(None)”을 반환한다.입력으로 네오가 기억한 멜로디를 담은 문자열 m과 방송된 곡의 정보를 담고 있는 배열 musicinfos가 주어진다.
m은 음 1개 이상 1439개 이하로 구성되어 있다.musicinfos는 100개 이하의 곡 정보를 담고 있는 배열로, 각각의 곡 정보는 음악이 시작한 시각, 끝난 시각, 음악 제목, 악보 정보가 ','로 구분된 문자열이다.
HH:MM 형식이다.,' 이외의 출력 가능한 문자로 표현된 길이 1 이상 64 이하의 문자열이다.1개 이상 1439개 이하로 구성되어 있다.조건과 일치하는 음악 제목을 출력한다.
let output = solution("ABCDEFG", ["12:00,12:14,HELLO,CDEFGAB", "13:00,13:05,WORLD,ABCDEF"]);
console.log(output); // "HELLO"
output = solution("CC#BCC#BCC#BCC#B", ["03:00,03:30,FOO,CC#B", "04:00,04:08,BAR,CC#BCC#BCC#B"]);
console.log(output); // "FOO"
output = solution("ABC", ["12:00,12:14,HELLO,C#DEFGAB", "13:00,13:05,WORLD,ABCDEF"]);
console.log(output); // "WORLD"
function solution(m, musicinfos) {
const musicList = [];
while (musicinfos.length > 0) {
const currInfo = musicinfos.shift();
const numbers = currInfo.match(/[0-9]+/g);
const strings = currInfo.split(',').slice(2);
let playHour = numbers[2] - numbers[0];
let playTime = numbers[3] - numbers[1];
if (playHour !== 0) playTime += playHour * 60;
let sheet = strings[1].replace(/[A-Z]#/g, char => {
return char[0].toLowerCase();
});
let share = parseInt(playTime / sheet.length);
let rest = playTime % sheet.length;
sheet = sheet.repeat(share) + sheet.slice(0, rest);
let newM = m.replace(/[A-Z]#/g, char => {
return char[0].toLowerCase();
});
if (sheet.includes(newM)) {
musicList.push([playTime, strings[0]]);
}
}
if (musicList.length === 0) return '(None)';
const result = musicList.sort((a, b) => b[0] - a[0]);
return result[0][1];
}