w2d5 Flashcards

1
Q

What does the Comparable module do?

A

Allows objects of the same type to be compared using standard comparison operators

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

What module allows you to compare objects of the same type?

A

Comparable

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

How do you return an array of objects when you need to loop over an array?

A

Array#map

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

How do you iterate an array over a particular range (style issue)?

A

arr[start_i..end_i].each { … }

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

What is linearithmic time?

A

n * log(n)

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

How do you describe the time complexity of n * log(n) ?

A

Linearithmic

Log-linear

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

CSS: How do you target elements with specific attributes? Say, input with type radio?

A

input[type=”radio”] { … }

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

What is a css reset used for?

A

To overwrite the browser’s built-in user style sheet.

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

What’s a css state selector? How would you select one while hovering over a button?

A

A selector that will selectively apply based on the item’s current state.

button:hover { … }

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

How do you select every other instance of an element?

A

element:nth-of-type(2n) { … }

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

How do you select every other instance of an element, starting with the 2nd element?

A

element:nth-of-type(2n + 1) { … }

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

How do you select all siblings that follow a particular element?

Example: all p’s that follow a div

A

div ~ p { … }

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

How do you select the first child and only the first child?

Example: first img within a header

A

header img:first-child { … }

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

What’s the difference between these two selectors:

div p { … }
div > p { … }

A

The first applies to all descendants.

The second applies only to children. Not to grandchildren, etc.

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

How does a Set obtain O(1) access time? When would the access time be more?

A

It mods each element into buckets.

If all elements are divisible by the same modulus, access will not be O(1), but O(n).

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

How does a Set obtain O(1) insertion time?

A

When there are empty buckets, insertion only requires a mod and an assignment to perform.

When there are no empty buckets, it takes n time to re-mod each existing element, constant time to double the number of buckets, and n time to perform n reassignments.

So then every n inserts, we perform n constant time operations and one n-time resize. On average, this is n/n time which is O(1).

That said, when we have a full set, the next insert will take n time to perform.

17
Q

What’s a Set’s time complexity given a pathological input?

A

O(n)

18
Q

why is it important to implement #hash in a complex object?

A

to allow Hash and Set to work correctly

19
Q

how do you facilitate Hash and Set to work with complex objects?

A

override #hash

20
Q

how does a LRU Cache get away with O(1) time on all methods?

A

hash map for reading/writing

linked list for deletions

21
Q

what’s the fastest hashing function?

A

xor

22
Q

CSS: what’s a way to compute the width of an element?

A

border-left + padding-left + content + padding-right + border-right

23
Q

draw the box model from outer to inner

A

margin
border
padding
content

24
Q

how do you add red lines to reach element in a page,,

A
  • { border: 1px soliid red; }
25
Q

is margin additive? will two boxes with 50px have 100px between them or 50px?

A

non- additive

50px