S
S
Stanislav Ponomarev2020-04-19 13:13:09
JavaScript
Stanislav Ponomarev, 2020-04-19 13:13:09

What does the abbreviation in function mean?

I have a factorial function

function factorial(n) {
  return (n < 2) ? 1 : factorial(n - 1) * n;
}


what does this entry mean: factorial(n - 1)? How else to write it down?

Thanks everyone, got it)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Tigran Abrahamyan, 2020-04-19
@Chelentano93

As already said, this is recursion, this factorial code can be rewritten somehow like this.

function factorial(n) {
  let f = 1;

  for (let i = 2; i <= n; i++) {
    f *= i;
  }

  return f;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question