function findBlackNumber(arr, N) {
    let blackPoint = [];
    let blackTotal = getBlackNumber(arr);
    let blackMap = getBlackMap(arr);
    let matchY = getMatchY(arr, blackMap);
    console.log(matchY);
    for (let i = 0; i < arr.length; i++) {
        for (let j = 0; j < arr[i].length; j++) {
            if (blackTotal.x[i] === blackTotal.y[j]
                && blackTotal.x[i] === N
                && arr[i][j] === 'B'
                && matchY[j] === 1
            ) {
                blackPoint.push([i, j]);
            }
        }
    }
    return blackPoint;
}

function getBlackMap(arr) { 
    let result = {};
    for (let i = 0; i < arr.length; i++) { 
        let value = arr[i].join('');
        result[i] = value;
    }
    return result;
}

function getMatchY(arr, blackMap) {
    let result = new Array(arr[1].length).fill(0);
    for (let i = 0; i < result.length; i++) {
        let _tempValue = '';
        let metch = true
        for (let j = 0; j < arr.length; j++) {
            let _result = true
            for (let k = 0; k < arr[j].length; k++) {
                if (i === k && blackMap[j][k] === 'B') { 
                    if (!_tempValue) { 
                        _tempValue = blackMap[j];
                    } else if (_tempValue !== blackMap[j]) { 
                        _tempValue = '';
                        _result = false;
                        break;
                    }
                }
            }
            if (!_result) { 
                metch = false;
                break;
            }
        }
        if (metch) { 
            result[i] = 1;
        }
    }
    return result;
}

function getBlackNumber(arr) { 
    let result = {x: new Array(arr.length).fill(0), y: new Array(arr[1].length).fill(0)};
    let arrY = new Array(arr[1].length).fill(0);
    for (let i = 0; i < arr.length; i++) {
        let _numberX = arr[i].filter(item => item === 'B').length;
        result.x[i] = _numberX;
    }
    for (let i = 0; i < arrY.length; i++) {
        for (let j = 0; j < arr.length; j++) {
            for (let k = 0; k < arr[j].length; k++) {
                if (i === k && arr[j][k] === 'B') {
                    result.y[i] += 1
                }
            }
        }
    }
    return result;
}

const a = [
    ['w', 'B', 'w', 'B', 'B','w'],
    ['w', 'B', 'w', 'B', 'B','w'],
    ['w', 'B', 'w', 'B', 'B','w'],
    ['w', 'w', 'B', 'w', 'B','w'],
]
const b = [
    ['w', 'B', 'w', 'B', 'B','w'],
    ['w', 'B', 'w', 'B', 'B','w'],
    ['w', 'B', 'w', 'B', 'B','w'],
    ['B', 'w', 'B', 'w', 'W','B'],
    ['B', 'w', 'B', 'w', 'W','B'],
    ['B', 'w', 'B', 'w', 'W','B'],
]


console.log(findBlackNumber(b, 3));

