3 ms·
Learn shell programming (https://tldp.org/LDP/Bash-Beginners-Guide/html/sect_09_07.html https://tldp.org/LDP/Bash-Beginners-Guide/html/sect_09_07.ht...) or MS-D
by Someone 3y ago
Learn shell programming (https://tldp.org/LDP/Bash-Beginners-Guide/html/sect_09_07.html https://tldp.org/LDP/Bash-Beginners-Guide/html/sect_09_07.ht...) or MS-DOS (https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/shift https://learn.microsoft.com/en-us/windows-server/administrat...), and it won’t be a problem remembering what shift does.
Neither of those has unshift, but you can infer its meaning from knowing about shift.
I also think push and pop aren’t good names. append, respectively removelast are way better.
- sargstuff 3y agolifo: last in, first out (cafeteria food line) -- taking from front/top, adding to back/bottom -- enought shifts will push element out of array queue without need to 'unshift' fifo : first in, first out (stack of plates) -- taking from front/top, adding to front/top. -- shift on "1"/push; unshift off "0"/pop. start with at least one shift/push. ideally equal number of unshifts/pops by end of task to clear the stack array.
- wrboyce 3y agoYou have these the wrong way around. LIFO is a stack, FIFO is a queue.
- brudgers 3y ago"append" means adding something to the back end, e.g. appendices in a book are encountered later when sequentially processing the book's pages. "prepend" is used to describe adding something at the beginning of a sequence. Good old "cons" has the specific technical meaning of placing data at the lowest address of a sequential memory structure...and it is shorter than "append" and "prepend."
- sargstuff 3y ago'idice' is the specific location context to put at end.
- galaxyLogic 3y agoYes append() and prepend() would be much better names than push() and unshift(). IF JavaScript had them as built-ins it would be great, then I wouldn't need to look for mnemonics for shift() and unshift() :-) But, I googled "prepend" and guess what: google replied "Although it sounds correct, prepend is not an English word. It was created to sound like the opposite of "append," which means to add to the end. The correct English word is "prefix". A slight problem with that is that "prefix" is more often used as a noun than as a verb, I think.
- brudgers 3y ago"Prepend" might not be queen's English. I'm American so so what. Anyway, "cons" is a better term in technical contexts.
- galaxyLogic 3y agoI agree that append() and removeLast() would be better names. But they don't exist as built-in functions in JavaScript. Therefore I need a mnemonic that makes it easy for me to remember what shift() and unshift() do.
- gabrielsroka 3y agoTry Array.prototype.append = Array.prototype.push; Etc
- galaxyLogic 3y agoThat is tempting, and I've dome similar things earlier. But I don't want to do that. Why because: It is not a good practice to modify JavaScript built-in prototypes. If that was the recommended practice then someone else's code might do a similar thing, but assign some other function to it. Whoever writes it last overrides any previous definition.
- gabrielsroka 3y ago> someone else's code I don't use someone else's code. I use my code. But I may be the minority. Use a namespace, then. Array.prototype.glAppend = Array.prototype.push;