You are viewing a single comment's thread. Return to all comments →
Here's how i implemented the same solution without using object oriented javascript
function processData(input) { var is = input.split("\n"); var giver = []; var taker = []; for (var i = 1; i < is.length; i++) { if (is[i][0] === "1") { var value = is[i].slice(1).trim(); taker.push(value); } if (is[i][0] === "2") { if (giver.length > 0) giver.pop(); else { while (taker.length !== 0) giver.push(taker.pop()); giver.pop(); } } if (is[i][0] === "3") { if (giver.length > 0) console.log(giver[giver.length-1]); else { while (taker.length !== 0) giver.push(taker.pop()); console.log(giver[giver.length-1]); } } } }
Seems like cookies are disabled on this browser, please enable them to open this website
Queues: A Tale of Two Stacks
You are viewing a single comment's thread. Return to all comments →
Here's how i implemented the same solution without using object oriented javascript