fork download
  1. const smallestDivisor = (num) => {
  2. // BEGIN
  3. const iter = (acc) => {
  4. // We use 'num / 2' in the condition below, and not 'num'.
  5. // This is a simple optimization: a number cannot be divided
  6. // by a number larger than its half.
  7. if (acc > num / 2) {
  8. return num;
  9. }
  10. if (num % acc === 0) {
  11. return acc;
  12. }
  13. return iter(acc + 1);
  14. };
  15.  
  16. return iter(2);
  17. // END
  18. };
Success #stdin #stdout 0.02s 10616KB
stdin
Standard input is empty
stdout
Standard output is empty