DEV Community

Minh Hieu
Minh Hieu

Posted on

Drawing Book Explain - Solution | Javascript

function pageCount(n, p) {
    /*
     * Write your code here.
     */
  const isFromLast = (n - p) <= (p-1);
  if (isFromLast) {
    if (n % 2 === 0) {
      return Math.ceil((n - p) / 2)
    }
    return Math.floor((n - p) / 2)
  } else {
    return Math.floor(p/2);
  }
}

pageCount(7, 4);

Problem

Top comments (0)