Beat Mix synthesizer bonus

[https://www.codecademy.com/paths/create-a-back-end-app-with-javascript/tracks/bapi-javascript-arrays-loops-and-iterators/modules/project-beat-mix/informationals/bapi-p2-beat-mix-solution]

I am having trouble with the bonus synthesizer. I get error that my array length in wrong when node is located in corner or edge. When I console.log the out array I get the appropriate output. I can not sort out where the problem is.

const getPrimary = (x, y) => {
    
    if (x < 0 || x > maxDim || y < 0 || y > maxDim) {
        return neighborsArray;
    } else {
        return primary = [x, y];
    }
}
const getNeighbors = () => {
    if (!primary) {
        return neighborsArray;
    } else {
        if (primary[0] > 0) {
            xLeft = primary[0] - 1;
        }
        if (primary[0] < maxDim) {
            xRight = primary[0] + 1;
        }
        if (primary[1] > 0) {
            yBelow = primary[1] - 1;
        }
        if (primary[1] < maxDim) {
            yAbove = primary[1] + 1;
        }
    }
    
}
const getNeighborPads = (x, y, size) => {
    if (size) {
        maxDim = size - 1;
    } else return neighborsArray;
    
    getPrimary (x,y);
    getNeighbors ()
    
    if (xLeft >= 0 && xLeft <= maxDim) {
        neighborsArray.push ([xLeft, y]);
       
    } 
    if (xRight >= 0 && xRight <= maxDim) {
        neighborsArray.push( [xRight, y]);
        
    }
    if (yAbove >= 0 && yAbove <= maxDim) {
        neighborsArray.push([x, yAbove]);
    
    }
    if (yBelow >= 0 && yBelow <= maxDim) {
        neighborsArray.push([x, yBelow]);
    }
    
    return neighborsArray;
    
}

The error messages:

  1. should only return two neighbors when called with a location in a corner of the grid
  2. should only return three neighbors when called with a location on the edge of the grid
    Thanks