You are viewing a single comment's thread. Return to all comments →
function getMax(operations) { let arr = [], results = []; operations.forEach(element => { if (element.startsWith("1")) { arr.push(element.split(" ")[1]) } else if (element.startsWith("2") && arr.length !== 0) { arr.pop() } else if (element.startsWith("3")) { let max = Math.max(...arr); results.push(max); } }); return results; }
Seems like cookies are disabled on this browser, please enable them to open this website
Maximum Element
You are viewing a single comment's thread. Return to all comments →
function getMax(operations) { let arr = [], results = []; operations.forEach(element => { if (element.startsWith("1")) { arr.push(element.split(" ")[1]) } else if (element.startsWith("2") && arr.length !== 0) { arr.pop() } else if (element.startsWith("3")) { let max = Math.max(...arr); results.push(max); } }); return results; }