Last active
September 10, 2018 14:31
-
-
Save aykutyaman/46179acaae6fc01f3f5520bac7ce7346 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const sum = ([x, ...xs]) => ( | |
xs.length === 0 | |
? x | |
: x + sum(xs) | |
); | |
console.log(sum([2, 4, 6])); // 12 | |
const count = ([x, ...xs]) => ( | |
xs.length === 0 | |
? 1 | |
: 1 + count(xs) | |
); | |
console.log(count([3, 6, 7, 4, 11, 39, 19])); // 7 | |
const max = (x, y) => x > y ? x : y; | |
const maximum = ([x, ...xs]) => ( | |
xs.length === 0 | |
? x | |
: max(x, maximum(xs)) | |
); | |
console.log(maximum([1, 339, 22, 31, 5, 7])); // 339 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment