Skip to content

Instantly share code, notes, and snippets.

@aykutyaman
Last active September 10, 2018 14:31
Show Gist options
  • Save aykutyaman/46179acaae6fc01f3f5520bac7ce7346 to your computer and use it in GitHub Desktop.
Save aykutyaman/46179acaae6fc01f3f5520bac7ce7346 to your computer and use it in GitHub Desktop.
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