Tuesday Flashcards
(4 cards)
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.
false, 0, null, undefined, ‘’, NaN
Math.floor (num)
Math.ceil (num)
Math.round (num)
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?
.includes ( )
.indexOf ( ), where -1 is returned if val not present
replace
replaceAll
difference between the postfix and the prefix increment operator
create a tally of these values using the reduce method :
const fruitBasket = [‘banana’, ‘cherry’, ‘orange’, ‘apple’, ‘cherry’, ‘orange’, ‘apple’, ‘banana’, ‘cherry’, ‘orange’, ‘fig’ ];
const count = fruitBasket.reduce( (tally, fruit) => {
tally[fruit] = (tally[fruit] || 0) + 1 ;
return tally;
} , {})