# A Faster Way to Compute Factors

A conceptually simple and straight-forward way to calculate the factors of a given number `n`

, might look like the below code:

# ruby

def factors(n)

(1..n).select { |int| n % int == 0 }

end// javascript

function factors(n) {

return Array(n).fill().map((_, idx) => idx + 1)

.filter(int => n % int === 0);

}

These code samples do the job. They iterate through an inclusive list of numbers 1 through `n`

, selecting only those numbers by which `n`

can be divided evenly. The returned result is an array of `n`

's…