Find minimum distance bugged

The function minDist() takes an array of coordinates from an object, iterates over those coordinates, and returns the smallest distance from the coordinates to a filled cell(a value of 1) in a 10x20 array. The return value is then added to the object’s y value. It seems to work correctly, but when I perform the function .rotate(), which alters the object’s coordinates, and then perform the function minDist(), the loops within minDist() seem to iterate much longer than they’re supposed to, resulting in the y-value of an object getting really weird. I’m not sure if there’s a problem with .rotate() or minDist(). Both the functions and the object they’re being performed on are being exported to another file called keys.js. Not sure if there’s some sort of error in importing/updating the values of certain variables being passed between the two files. It seems like the object’s coordinates are having trouble being updated.

//rotate function
    let store = [];
    //dir=0:cw dir=else:ccw
      for(let a = 0; a < this.piece.length; a++){
      for(let a = 0; a < this.piece.length; a++){
    this.piece = store;
//function minDist
export let minDist = function(obj){
  let p = obj.piece
  let min = Infinity;
  let track = 0;
  for(let b = 0; b < p.length; b++){
    for(let a = obj.y+p[b][1]; a < grid.length; a++){
        let dist = (a-obj.y+p[b][1]);
        if(dist < min){
          min = dist