Advertisement
Guest User

Untitled

a guest
May 5th, 2017
693
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function processCommands(commands) {
  2.     let command = (function () {
  3.         let text = '';
  4.         return {
  5.             append: (t)=>text = text + t,
  6.             removeStart: (count)=>text = text.slice(count),
  7.             removeEnd: (count)=>text = text.slice(0, text.length - count),
  8.             print: function () {
  9.                 console.log(text);
  10.             }
  11.         };
  12.     })();
  13.     for (let cmd of commands) {
  14.         let [cmdName, arg] = cmd.split(' ');
  15.         command[cmdName](arg);
  16.     }
  17.  
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement