Created
January 28, 2018 12:23
-
-
Save vadimkorr/d7c2c404f92b6b6cba085a8302abd521 to your computer and use it in GitHub Desktop.
Amount of even numbers in range
This file contains 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
// Find amount of even numbers X in range: A <= X <= B | |
let find = (a, b) => { | |
return Math.floor((b - a) / 2) + (a%2==0 || b%2==0 ? 1 : 0) | |
} | |
console.log(find(1, 5)) // 2 | |
console.log(find(1, 4)) // 2 | |
console.log(find(2, 5)) // 2 | |
console.log(find(2, 4)) // 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment