Cleaned up the current snippets for consistency and minor problems, added multiple tags to most of them, archived a few.
14 lines
195 B
Markdown
14 lines
195 B
Markdown
### collatz
|
|
|
|
Applies the 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);
|
|
```
|
|
|
|
```js
|
|
collatz(8); // 4
|
|
```
|