diff --git a/snippets/collatz-algorithm.md b/snippets/collatz-algorithm.md new file mode 100644 index 000000000..730bdd9e3 --- /dev/null +++ b/snippets/collatz-algorithm.md @@ -0,0 +1,9 @@ +### 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 +``` diff --git a/snippets/collatz.md b/snippets/collatz.md deleted file mode 100644 index f92718b6c..000000000 --- a/snippets/collatz.md +++ /dev/null @@ -1,11 +0,0 @@ -### Collatz algorithm - -If n even then returns **n/2** otherwise (n is odd) **3n+1**. -It uses the ternary operator. - -``` js - const collatz = n => (n % 2 == 0) ? (n/2) : (3*n+1); - // collatz(8) --> 4 - // collatz(5) --> 16 - -``` \ No newline at end of file