Recursion and stack Flashcards

1
Q

A partial case of this is when a function calls itself. That’s called _______.

A

recursion

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

function pow(x, n) {
let result = 1;
for (let i = 0; i < n; i++) {
result *= x;
}
return result;
}

write the above in a shorter way
function pow(x, n) {
/* coder here */
}

A

return (n == 1) ? x : (x * pow(x, n - 1));

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