Challenge 13 problem only on website


#1

I can run it on my own machine and it produces the exact same result as what is expected, even down to the order of the coordinates, but the website doesn’t seem to like it. Here is my code:

const height = GRID.length;
const width = GRID[0].length;
const cols = 'ABCDEFGHIJ';
const tRows = [1,2,3,4,5,6,7,8,9,10];
const rows = tRows.map(x => String(x));

function convertColumn(coord) {
  return(cols.indexOf(coord[0]))
}

function lightCell(coord) {
  if ((cols.indexOf(coord[0]) != -1) && (rows.includes(coord.slice(1)))) {
    return(GRID[parseInt(coord.slice(1))-1][convertColumn(coord)])
  } else {
    return(false)
  }
}

isRock = (coord) => {
  if (lightCell(coord) == '^') {
    return(true)
  } else {
    return(false)
  }
}

isCurrent = (coord) => {
  if (lightCell(coord) == '~') {
    return(true)
  } else {
    return(false)
  }
}

isShip = (coord) => {
  if (lightCell(coord) == 'v') {
    return(true)
  } else {
    return(false)
  }
}

lightRow = (row) => {
  return(GRID[row-1])
}

lightColumn = (col) => {
  const colNum = convertColumn(col);
  var colContents = [];
  for (var i in GRID) {
    colContents.push(GRID[i][colNum])
  }
  return(colContents);
}

var allCoords = []
for (var i in cols) {
  for (var j in rows) {
    allCoords.push(cols[i] + rows[j]);
  }
}

allRocks = (grd) => {
  var rockCoords = [];
  allCoords.map(x => {
    if (isRock(x)) {
      rockCoords.push(x);
    }
  })
  rockCoords.sort((a, b) => {
    return(a.slice(1) - b.slice(1));
  })
  return(rockCoords);
}

allCurrents = (grd) => {
  var currentCoords = [];
  allCoords.map(x => {
    if (isCurrent(x)) {
      currentCoords.push(x);
    }
  })
  currentCoords.sort((a, b) => {
    return(a.slice(1) - b.slice(1));
  })
  return(currentCoords);
}

Sorry, some of the earlier stuff is messy and inconsistent with the rest of the code. Could anyone let me know where I’m going wrong? Thanks.


#2

I’m having the same issue! :confused: