Tuesday Flashcards

(4 cards)

1
Q

list the six falsy values.

also, describe how you’d use the Math object to remove a decimal from a number, round up a number, or round to the nearest integer.

A

false, 0, null, undefined, ‘’, NaN

Math.floor (num)
Math.ceil (num)
Math.round (num)

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

use a method to determine if the letter r is present in str.
how would you change all of the ‘o’s to ‘a’s and the first instance of ‘t’ to ‘c’?

use a different method to determine if 14 is present in arr. what do you expect to return?

A

.includes ( )
.indexOf ( ), where -1 is returned if val not present

replace
replaceAll

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

difference between the postfix and the prefix increment operator

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

create a tally of these values using the reduce method :

const fruitBasket = [‘banana’, ‘cherry’, ‘orange’, ‘apple’, ‘cherry’, ‘orange’, ‘apple’, ‘banana’, ‘cherry’, ‘orange’, ‘fig’ ];

A

const count = fruitBasket.reduce( (tally, fruit) => {
tally[fruit] = (tally[fruit] || 0) + 1 ;
return tally;
} , {})

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