From f92c6d4079c898ea5a9fa8f6b93d854a58234aaa Mon Sep 17 00:00:00 2001 From: Christian Bender Date: Wed, 13 Dec 2017 23:02:42 +0100 Subject: [PATCH 1/3] collatz algorithm collatz algorithm as function --- snippets/collatz.md | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 snippets/collatz.md diff --git a/snippets/collatz.md b/snippets/collatz.md new file mode 100644 index 000000000..120f96e27 --- /dev/null +++ b/snippets/collatz.md @@ -0,0 +1,11 @@ +### Collatz algorithm + +If n even then returns **n/2** otherwise (n is odd) **3n+1**. +It uses the ternary operator. + +``` javascript + const collatz = n => (n % 2 == 0) ? (n/2) : (3*n+1); + // collatz(8) --> 4 + // collatz(5) --> 16 + +``` \ No newline at end of file From e44fef2a2a24b5ba01d2e985365837e6ba8bf15f Mon Sep 17 00:00:00 2001 From: Christian Bender Date: Thu, 14 Dec 2017 13:48:57 +0100 Subject: [PATCH 2/3] changed I changed 'javascript' in 'js' --- snippets/collatz.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/collatz.md b/snippets/collatz.md index 120f96e27..f92718b6c 100644 --- a/snippets/collatz.md +++ b/snippets/collatz.md @@ -3,7 +3,7 @@ If n even then returns **n/2** otherwise (n is odd) **3n+1**. It uses the ternary operator. -``` javascript +``` js const collatz = n => (n % 2 == 0) ? (n/2) : (3*n+1); // collatz(8) --> 4 // collatz(5) --> 16 From 421f4f46a8b0e832924edb6d58729af9f240b8f7 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Thu, 14 Dec 2017 14:51:44 +0200 Subject: [PATCH 3/3] Update and rename collatz.md to collatz-algorithm.md --- snippets/collatz-algorithm.md | 9 +++++++++ snippets/collatz.md | 11 ----------- 2 files changed, 9 insertions(+), 11 deletions(-) create mode 100644 snippets/collatz-algorithm.md delete mode 100644 snippets/collatz.md 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