Ad. Javascript.info part 3 Flashcards
Advanced working with functions
two ways of thinking in javascript
Iterative thinking: the for loop:
Recursive thinking: simplify the task and call self:
Generally what is shorter solution, recursive solution or iterative solution?
A recursive solution
___________ is an internal data structure that contains details about the execution of a function
The execution context
__________ algorithm is more memory-saving:
A loop-based iteration Iterative
_________ 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.
The next()
function sum(a, b) { return a + b; }
alert( sum(1, 2, 3, 4, 5) );
RETRUNS
3
The “rest parameters” can be mentioned in a function definition with ______
three dots
function sumAll(...args) { let sum = 0;
for (let arg of args) sum += arg;
return sum;
}
alert( sumAll(1, 2, 3) ); //
6
function sumAll(\_\_\_\_\_\_\_\_\_\_\_\_) { <=== use spread operator let sum = 0;
for (let arg of args) sum += arg;
return sum;
}
alert( sumAll(1, 2, 3) ); //
…ARG
The …rest must always be ________
LAST
Arrow functions do not have an array-like object named _________ as well as _________
arguments method
this
function f(arg1, ...rest, arg2) { }
// RETURNS?
// error
…rest needs to be at the end
arrow functions do not have “arguments” because
it takes them from the outer “normal” function.
let arr = [3, 5, 1];
alert( Math.max(arr) ); //
NAN
max cant manually list items in the code
let arr = [3, 5, 1];
alert( Math.max(…arr) //
5