Skip to content

Instantly share code, notes, and snippets.

@mildfuzz
Last active December 12, 2016 08:16
Show Gist options
  • Select an option

  • Save mildfuzz/c5e64b634e6aa61006751a1a8b746650 to your computer and use it in GitHub Desktop.

Select an option

Save mildfuzz/c5e64b634e6aa61006751a1a8b746650 to your computer and use it in GitHub Desktop.
Factorise integers. Use the list of factors to find highest and lowest common denominators
function factors(x: number): number[] {
const f = [];
for(let i = 2; (i*i) <= x; i++) {
if(x % i === 0) {
f.push(i);
}
}
return f;
}
function lowComDom(x: number, y: number): number {
const xF: number[] = factors(x);
const yF: number[] = factors(y);
return xF.find( i => yF.indexOf(i) >= 0)
}
function highComDom(x: number, y: number): number {
const xF: number[] = factors(x);
const yF: number[] = factors(y);
return xF.reverse()find( i => yF.indexOf(i) >= 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment