Saturday Flashcards

(5 cards)

1
Q

Object constructor methods
assign
entries
keys
values
hasOwnProperty

A

assign —

entries —

keys —- returns the keys in an object in an array as string elements

values — returns the values in an object in an array

hasOwnProperty —- a method that checks for the presence of a key (passed in as an argument) & returns a boolean

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

describe three ways to enumerate an object

A

for…in loop
for (let nameRepresentingEachKey of objectName) {
body
};

for…of loop with Object methods
for (let [key, value] of Object.entries(objName)) **
for (let value of Object.values(objName)) **
for (let key of Object.keys(objName))

array method with Object methods
Object.keys(obj).forEach(key => { functionality });
*** remember that keys are automatically stored as strings when pulled from an object literal… if you need to act on or pass the numeric version of a key (if keys are numbers in the object), you have to convert the number (or variable holding the number) to a string value using parseInt function

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

array methods
forEach
map

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

find max (not using Math methods) and min (using Math method) using reduce

const grades = [87, 64, 96, 92, 88, 99, 73, 70, 64];

A

const maxGrade = grades.reduce ((max, currVal) => {
if(currVal > max) return currVal;
return max;
});
console.log(maxGrade)
ORRRRR
const maxGrade = grades.reduce((max, currVal) => max > currVal ? max : currVal);
console.log(maxGrade);

const minGrade = grades.reduce ((min, currVal) => {
return Math.min(min, currVal);
});
console.log(minGrade);

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

pass by value vs pass by reference

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