Senior Side Week 5 Flashcards
What does the acronym LIFO mean?
It stands for “last-in-first-out”. 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?
push(value) - adds a value to the “top” of the stack.
pop - removes the top value from the stack and returns it.
peek - returns the “top” value of the stack without removing it.
What must you do to access the value at an arbitrary point in a stack (not just the “top”)?
Pop until you get there.
What does the acronym FIFO mean?
“First in First Out”.
The first thing 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(value) - removes the “front” value from the queue and returns it
peek() - looks at the “front” value
What must you do to access the value at an arbitrary point in a queue (not just the “front”)?
dequeue until you find the value that you want
How are linked lists different from an array?
Linked lists are sequential access (like a queue), not random access (like an array). That means that, in order to go to a specific place in the list, you have to start at the beginning, then jump from node to node until you get there. However, unlike a queue, a linked list doesn’t need to be mutated to scan its contents.
How would you access an arbitrary node in a linked list (not just the “head”)?
.next
What are unit tests?
A unit test is a way of testing a unit - the smallest piece of code that can be logically isolated in a system. In most programming languages, that is a function.
Why is it important to write unit tests?
Test Driven Development - is a code design technique where the programmer writes a test before any production code, and then writes the code that will make that test pass
Checking your work
Code Documentation
In general, the goal of unit testing is to ensure that small, isolated pieces of code are functioning correctly. This can help catch bugs and prevent regressions as code is developed and updated over time.
What code should be tested with a unit test? What code is not well suited for unit tests?
Unit tests should only test exported functions and methods.
In general, the goal of unit testing is to ensure that small, isolated pieces of code are functioning correctly. This can help catch bugs and prevent regressions as code is developed and updated over time.
What is Jest? What are some other popular JavaScript unit testing frameworks?
Jest is a JavaScript testing framework.
Mocha
Jasmine
Ava
Tape
Karma
In JavaScript, when is scope determined?
In JavaScript, scope is determined at the time of function creation. This means that the variables and functions declared within a function are only accessible within that function’s scope and any nested functions, but not outside of it.
What allows JavaScript functions to “remember” values from their surroundings?
In JavaScript, functions have access to variables declared in their outer, or surrounding, scopes. This is known as “lexical scoping” or “closure”.
When a function is defined, it has access to the variables in its parent scope (i.e., the scope in which it was defined), as well as any higher-level parent scopes. This is because functions are defined with a reference to their surrounding lexical environment, which includes all the variables and functions in the scope where they were created.
This means that even after the outer function has completed its execution and its variables have gone out of scope, the inner function may still “remember” the values of those variables because it has access to its surrounding scope.
This behavior can be useful for creating functions that encapsulate certain values or behavior, allowing them to be reused and composed in different ways. It’s also important to understand how closures work in JavaScript to avoid unintended side effects and to write more maintainable and organized code.
What values does a closure contain?
The closure “remembers” the values of the variables in its surrounding lexical environment at the time the inner function was defined. This means that even if the outer function has completed its execution and its variables have gone out of scope, the inner function can still access those values through the closure.