![]() |
[Hackerrank] Solution of Drawing Book in JavaScript |
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
function pageCount(n, p) { | |
/* | |
* Write your code here. | |
*/ | |
const pageFromStart = Math.floor(p/2); | |
const pageFromEnd = Math.ceil(((n % 2 !== 0 ? n - 1 : n) - p)/2); | |
return Math.min(pageFromStart, pageFromEnd); | |
} |