Files
30-seconds-of-code/snippets_archive/collatz.md
2018-02-04 17:48:07 +02:00

196 B

collatz

Applies the Collatz algorithm.

If n is even, return n/2. Otherwise, return 3n+1.

const collatz = n => (n % 2 === 0 ? n / 2 : 3 * n + 1);
collatz(8); // 4