Javascript solution using Math.sqrt and Array.unshift


My solutions follows the video by using the Math.sqrt() function for my iterator, and then I hold two separate arrays for the “first factor” and then its pair. The pairs will be found in decreasing order, so I use Array.unshift instead of Array.push, and just concat these two at the end. Not the most efficient for memory I’m sure, but was an easy way to think about it for me.

let firstFactors = [];
let secondFactors = [];
    for (let i = 1; i <= Math.sqrt(A); i++) {
        if (A % i === 0) {
            if (i !== Math.sqrt(A)) {
  return firstFactors.concat(secondFactors);


But unshift itself will have complexity as equal to the length of secondFactors array