Skip to content

Instantly share code, notes, and snippets.

@lubien
Forked from ronaiza-cardoso/show-me.js
Last active March 14, 2017 17:26
Show Gist options
  • Save lubien/ba700ca513af78ab55f408b5aa40c4fa to your computer and use it in GitHub Desktop.
Save lubien/ba700ca513af78ab55f408b5aa40c4fa to your computer and use it in GitHub Desktop.
Show Me the Evens - Show me the Odds
/**
* Show Me the Evens - Show me the Odds
* Diana is learning to count and she just learned the difference between odds and even numbers.
* She wants to have some fun, so she picks a random number.
* If that number is even, she decides to count all the even numbers up to it starting from 0 up to (but not including) the input.
* If not, she decides to count all the odd numbers up to that number starting from 1 (but not including) the input.
**/
const
range = x => y =>
Array.from({length: (y - x)})
.map((_, i) => i + x)
, filter = f => xs =>
xs.filter(f)
, even = x =>
(x % 2) === 0
, odd = x =>
!even(x)
// Inspired by: https://gist.github.com/anabastos/db389fbd9c3d830fd550ca21fb07271e
, showMe = x =>
filter(even(x) ? even : odd)(range(0)(x))
showMe(10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment