Data Structures Flashcards
What does the acronym LIFO mean?
Last-In-First-Out operations: the last thing pushed onto the stack is the first thing that can be popped out.
What methods are available on a Stack data structure?
pop() - pops the “top” value off of the stack.
push() - pushes an item to the “top” of the stack
peek() - returns the “top” value without modifying it
What must you do to access the value at an arbitrary point in a stack (not just the “top”)?
Start at the top and traverse through with the next property
What does the acronym FIFO mean?
First-In-First-Out operations: the first thing in enqueued onto the queue is the first thing that can be dequeued out.
What methods are available on a Queue data structure?
enqueue(value) - adds a value to the “back” of the queue
dequeue() - removes the “front” value from the queue and returns it
peek() - returns the “front” value of the queue without removing it
What must you do to access the value at an arbitrary point in a queue (not just the “front”)?
dequeue() until you get to the point
What must the return value ofmyFunctionbe if the following expression is possible? myFunction()();
A function
What does this code do? const wrap = value => () => value;
wrap(1)(); //1
wrap(2)(); //2
Returns the value
wrap(value) {
return () => value;
};
function wrap(value) {
return function() {
return value;
};
};
In JavaScript, when is a function’s scope determined; when it is called or when it is defined?
Defined
What allows JavaScript functions to “remember” values from their surroundings?
Closures