Higher-Order Functions Flashcards

1
Q

What kind of function gets passed as an argument to another function?

A

Callback function

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

What kind of function accepts other functions as arguments?

A

Higher-order function

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

Operations started only after preceding ones have completed are

A

Synchronous

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

4 ways functions are data

A

Pass them to other functions
Set them as object properties
Store them in arrays
Set them as variables

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

Higher-order function that executes a function once for each array element

A
forEach()
var array1 = ['a', 'b', 'c'];
array1.forEach(function(element) {
  console.log(element);
});
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Higher-order function that creates a new array with the results of calling a provided function on every element in the calling array

A
map()
var array1 = [1, 4, 9, 16];
// pass a function to map
const map1 = array1.map(x => x * 2);
console.log(map1);
// expected output: Array [2, 8, 18, 32]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Higher-order function that creates a new array with all the elements that pass the test implemented by the provided function

A
filter()
var words = ['spray', 'limit', 'elite', 'exuberant', 'destruction', 'present'];

const result = words.filter(word => word.length > 6);

console.log(result);
// expected output: Array ["exuberant", "destruction", "present"]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Higher-order function that executes a provided reducer function on each element of the array resulting in a single output value

A
reduce()
const array1 = [1, 2, 3, 4];
const reducer = (accumulator, currentValue) => accumulator + currentValue;
// 1 + 2 + 3 + 4
console.log(array1.reduce(reducer));
// expected output: 10
// 5 + 1 + 2 + 3 + 4
console.log(array1.reduce(reducer, 5));
// expected output: 15
How well did you know this?
1
Not at all
2
3
4
5
Perfectly