Skip to content

Instantly share code, notes, and snippets.

@mrandrewmills
Created March 12, 2016 21:08
Show Gist options
  • Save mrandrewmills/db128c0109af5cb8c32b to your computer and use it in GitHub Desktop.
Save mrandrewmills/db128c0109af5cb8c32b to your computer and use it in GitHub Desktop.
returns factors for an integer
/**
* getFactors - find all factors of an integer in pairs
* @param, N, an integer
* returns a multidimensional array (e.g. 4 gets: [1,4],[2,2],[4,1])
*/
function getFactors(N) {
"use strict";
var x;
var pairNum, factors = [];
for (x = 1; x <= N; x++) {
if ( N % x == 0) {
var pairNum = [];
pairNum.push(x);
pairNum.push(N/x);
factors.push(pairNum);
}
}
return factors;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment