Type of Variable

Continuing the discussion from freeCodeCamp Challenge Guide: Smallest Common Multiple:

The factors variable has a memory persisting through different function calls. For example, when getPrimeFactors(4) is called, (for the test case [1, 5]) the factors[2] is incremented. It returns {‘2’: 2} instead of {‘2’: 1}.

What type of variable is factors? It is able to remember the previous getPrimeFactors(2) and return {‘2’: 2} for getPrimeFactors(4).

I would like to read the documentation and learn more, but I do not know what to look up.

  • its just an object, it will keep track of which number has previously showed up and increment it by 1, if not found in “factors” variable then it creates a new entry with that number with value of 1
  • for which code it returns so?
1 Like

Thank you for your response!

Solution 4 of the “…Guide: Smallest Common Multiple” linked in the original post is the code I’m referring to.

The object is initiated and set to empty for each function call. I still don’t understand how it returns {‘2’: 2}.

Why should it only have 2 appering once? 4 has a prime factorization of 2*2

I messed up when writing the tracing table. Thank you for your help

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.