sajad torkamani

You want a function that takes an integer and returns all its factors from one up to the number itself. Something like this:

factors(20) // [1, 2, 4, 5, 10, 20]
factors(121) // [1, 11, 121]

Here’s how:

const factors = (num) => {
  const factorsList = []

  for (let n = 1; n <= num; n++) {
    if (num % n === 0) {
      factorsList.push(n)
    }
  }

  return factorsList
}