Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

91
Visualizações
Finding the next valid cell in a grid

Consider a grid represented by an array = ["....X..", "X......"]
. means the cell is empty, and X means there is a wall. A person is moving from the top-left location towards the right, and if any obstacle is encountered or there is no valid square ahead, it takes a right turn and starts moving
I am trying to represent the location like [0,0,"right"] The will be the initial position and then it will move to [0,1,"right"]->[0,2,"right"]->[0,3,"right"]->[0,4,"right"] now there is an obstacle so it will change direction and reach [1,4,"down"]. I am looking to write a function in javascript given a position [x,y,direction] returns the next location
It's getting clumsier with a lot of if-else conditions. Is there an efficient way to write it, or may I change how I represent the positions?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda