You are viewing a single comment's thread. Return to all comments →
JS
Made it to pass all the tests like that. Not sure if the logic is optimal though
function pageCount(n, p) {
// Write your code here
let start = Math.ceil((p - 1) / 2);
let end;
n % 2 === 0 ? (end = Math.ceil((n - p) / 2)) : (end = Math.floor((n - p) / 2));
return start <= end ? start : end; }
Seems like cookies are disabled on this browser, please enable them to open this website
Drawing Book
You are viewing a single comment's thread. Return to all comments →
JS
Made it to pass all the tests like that. Not sure if the logic is optimal though
function pageCount(n, p) {
// Write your code here
let start = Math.ceil((p - 1) / 2);
let end;
n % 2 === 0 ? (end = Math.ceil((n - p) / 2)) : (end = Math.floor((n - p) / 2));
return start <= end ? start : end; }