• + 0 comments

    JavaScript :

    function pageCount(n, p) {
        // Write your code here
        let min = 1;
        let max = n % 2 == 0 ? n : n - 1
        
        for(let i = 0; i <= n ; i++){
            if(min >= p || max <= p){
                return i
            }
            min += 2;
            max -= 2;
        }
    
    }