Files
30-seconds-of-code/snippets_archive/collatz.md
Angelos Chalaris 611729214a Snippet format update
To match the starter (for the migration)
2019-08-13 10:29:12 +03:00

16 lines
226 B
Markdown

---
title: collatz
tags: math,beginner
---
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
```