링크 >>>
function solution(operations) {
let answer = [];
const queue = [];
operations.forEach(v => {
const oper = v.split(" ");
if (v.includes("I")) {
queue.push(parseInt(oper[1]))
}
if (v === 'D 1') {
const maxIndex = queue.findIndex(v => v === Math.max(...queue))
queue.splice(maxIndex, 1);
}
if (v === 'D -1') {
const minIndex = queue.findIndex(v => v === Math.min(...queue))
queue.splice(minIndex, 1);
}
})
if (queue.length) answer = [Math.max(...queue), Math.min(...queue)];
return answer.length ? answer : [0, 0]
};