You are viewing a single comment's thread. Return to all comments →
Please tell me what can be improved!
function processData(input) { const realInput = input.split('\n').slice(1)
let string = [] let history = [] const fns = { 1: (str, u) => { string.push(...str) if (!u) { history.push([2, str.length]) } }, 2: (num, u) => { const removedChars = string.slice(-num) string = string.slice(0, -num) if (!u) { history.push([1, removedChars]) } }, 3: (num) => { console.log(string[num - 1]) }, 4: () => { const currentAction = history[history.length - 1] if (currentAction) { fns[currentAction[0]](currentAction[1], true) history.pop() } }, 5: () => {} } realInput.forEach((value) => { const [ fn, v ] = value.split(' ') fns[fn](v) })
}
Seems like cookies are disabled on this browser, please enable them to open this website
Simple Text Editor
You are viewing a single comment's thread. Return to all comments →
Javascript
Please tell me what can be improved!
function processData(input) { const realInput = input.split('\n').slice(1)
}