Files
30-seconds-of-code/snippets/collatz.md
Stefan Feješ f559030eac fix naming
2017-12-17 15:41:31 +01:00

10 lines
190 B
Markdown

### Collatz algorithm
If `n` is even, return `n/2`. Otherwise return `3n+1`.
```js
const collatz = n => (n % 2 == 0) ? (n / 2) : (3 * n + 1);
// collatz(8) --> 4
// collatz(5) --> 16
```