Senior Side Week 5 Flashcards

1
Q

What does the acronym LIFO mean?

A

It stands for “last-in-first-out”. The last thing pushed onto the stack is the first thing that can be popped out.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What methods are available on a Stack data structure?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What must you do to access the value at an arbitrary point in a stack (not just the “top”)?

A

Pop until you get there.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does the acronym FIFO mean?

A

“First in First Out”.
The first thing enqueued onto the queue is the first thing that can be dequeued out

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What methods are available on a Queue data structure?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What must you do to access the value at an arbitrary point in a queue (not just the “front”)?

A

dequeue until you find the value that you want

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How are linked lists different from an array?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How would you access an arbitrary node in a linked list (not just the “head”)?

A

.next

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are unit tests?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Why is it important to write unit tests?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What code should be tested with a unit test? What code is not well suited for unit tests?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is Jest? What are some other popular JavaScript unit testing frameworks?

A

Jest is a JavaScript testing framework.

Mocha
Jasmine
Ava
Tape
Karma

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

In JavaScript, when is scope determined?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What allows JavaScript functions to “remember” values from their surroundings?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What values does a closure contain?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

When is a closure created?

A

A closure is created when a function is defined inside another function and the inner function has access to the outer function’s variables, even after the outer function has returned. When the outer function is executed, it creates a new scope and all the variables declared inside that scope are stored in memory. When the inner function is defined, it retains a reference to that scope, which is known as a closure.

17
Q

How can you tell if a function will be created as a closure?

A

The function must be defined inside another function.
The inner function must reference at least one variable from the outer function’s scope.

18
Q

In React, what is one important case where you need to know if a closure was created?

A

useState and useEffect