Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for [old] Letter Queue by bronya100
"use strict";
function letterQueue(commands){
return commands.reduce( (r,c) => {
let s = c.split( ' ' );
s[0] == 'PUSH' ? r.push( s[1] ) : r.shift();
return r;
},[]).join( '' );
}
var assert = require('assert');
if (!global.is_checking) {
assert.equal(letterQueue(["PUSH A", "POP", "POP", "PUSH Z", "PUSH D", "PUSH O", "POP", "PUSH T"]), "DOT", "dot example");
assert.equal(letterQueue(["POP", "POP"]), "", "Pop, Pop, empty");
assert.equal(letterQueue(["PUSH H", "PUSH I"]), "HI", "Hi!");
assert.equal(letterQueue([]), "", "Nothing");
console.log("Coding complete? Click 'Check' to review your tests and earn cool rewards!");
}
Dec. 3, 2017