Ad. Javascript.info part 3 Flashcards

Advanced working with functions

1
Q

two ways of thinking in javascript

A

Iterative thinking: the for loop:

Recursive thinking: simplify the task and call self:

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

Generally what is shorter solution, recursive solution or iterative solution?

A

A recursive solution

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

___________ is an internal data structure that contains details about the execution of a function

A

The execution context

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

__________ algorithm is more memory-saving:

A

A loop-based iteration Iterative

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

_________ method returns an object with two properties done and value. You can also provide a parameter to the next method to send a value to the generator.

A

The next()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
function sum(a, b) {
  return a + b;
}

alert( sum(1, 2, 3, 4, 5) );

RETRUNS

A

3

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

The “rest parameters” can be mentioned in a function definition with ______

A

three dots

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
function sumAll(...args) { 
  let sum = 0;

for (let arg of args) sum += arg;

return sum;
}

alert( sumAll(1, 2, 3) ); //

A

6

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
function sumAll(\_\_\_\_\_\_\_\_\_\_\_\_) { <=== use spread operator
  let sum = 0;

for (let arg of args) sum += arg;

return sum;
}

alert( sumAll(1, 2, 3) ); //

A

…ARG

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

The …rest must always be ________

A

LAST

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

Arrow functions do not have an array-like object named _________ as well as _________

A

arguments method

this

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q
function f(arg1, ...rest, arg2) { 
}

// RETURNS?

A

// error

…rest needs to be at the end

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

arrow functions do not have “arguments” because

A

it takes them from the outer “normal” function.

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

let arr = [3, 5, 1];

alert( Math.max(arr) ); //

A

NAN

max cant manually list items in the code

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

let arr = [3, 5, 1];

alert( Math.max(…arr) //

A

5

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

When using SPREAD OR REST, you are expanding a single variable into more

A

spread

17
Q

When using SPREAD OR REST, arguments, you are collapsing all remaining arguments of a function into one array:

A

REST

18
Q

let arr1 = [1, -2, 3, 4];
let arr2 = [8, 3, -8, 1];

alert( Math.max(…arr1, …arr2) ); //

A

8

19
Q

let arr1 = [1, -2, 3, 4];
let arr2 = [8, 3, -8, 1];

alert( Math.max(1, …arr1, 2, …arr2, 25) ); //

A

25

20
Q

let str = “Hello”;

alert( […str] );

// THIS RETURNS

A

H,e,l,l,o

21
Q

let str = “Hello”;

alert( …str ); //

A

H

22
Q

The SPREAD OR ARRAY.FROM operates only on iterables.

A

SPREAD

23
Q

SPREAD OR ARRAY.FROM operates on both array-likes and iterables.

A

ARRAY.FROM

24
Q

an example of a recursive solution is the ___ statement

A

If

25
Q

ARRAY.FROM

A

operates on both array-likes and iterables.

26
Q

SPREAD

A

operates only on iterables.