Skip to content

Instantly share code, notes, and snippets.

@fitsum
Last active April 26, 2024 05:24
Show Gist options
  • Save fitsum/9def3a9763a47e377841f388a5bc6a22 to your computer and use it in GitHub Desktop.
Save fitsum/9def3a9763a47e377841f388a5bc6a22 to your computer and use it in GitHub Desktop.
get next even or odd number given n
nextNumOfType = (n, d) => {
let opts = {true: {'even': 2,'odd': 1}, false:{'even': 1,'odd': 2}}
return n + opts[n%2 == 0][d];
}
nextNumOfType(3,'odd') // 5
nextNumOfType(3,'even') // 4
nextNumOfType(4,'odd') // 5
nextNumOfType(4,'even') // 6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment