Skip to content

Instantly share code, notes, and snippets.

@kungfux
Created November 27, 2016 17:52
Show Gist options
  • Select an option

  • Save kungfux/bc56fd3f7d226a696b1ad5beaa2d05f3 to your computer and use it in GitHub Desktop.

Select an option

Save kungfux/bc56fd3f7d226a696b1ad5beaa2d05f3 to your computer and use it in GitHub Desktop.
Find smaller divisor for number
export const smallestDivisor = (a) => {
if (a === 1)
return 1;
const findDivisor = (a, d) => {
if (a % d === 0)
return d;
else
return findDivisor(a, d + 1);
};
return findDivisor(a, 2);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment