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

109
Visualizações
return statement returns nothing in javascript

Given a square grid of characters in the range ascii[a-z], rearrange elements of each row alphabetically, ascending. Determine if the columns are also in ascending alphabetical order, top to bottom. Return YES if they are or NO if they are not.

  const gridOrig = ["ebacd", "fghij", "olmkn", "trpqs", "xywuv"];

  function gridChallenge(grid) {
    // Write your code here
    let gridOne = [];
    let gridTwo = [];
    for (let i = 0; i < grid.length; i++) {
      gridOne.push(grid[i].split(""));
      // console.log(gridOne);
    }//this section makes each element of the array become array

    for (let i = 0; i < gridOne.length; i++) {
      gridTwo.push(gridOne[i].sort());
      // console.log(gridTwo);
    }//this section sort each element of the parent array

    let answer = [];

    for (let i = 0; i < gridTwo.length - 1; i++) {
      for (let j = 0; j < gridTwo[i].length; j++) {
        if (gridTwo[i][j] <= gridTwo[i + 1][j]) {
          // debugger;
          // console.log("true");
          answer.push("YES");
        } else if (undefined) {
          answer = "NO";
        } else {
          // console.log("false");
          answer.push("NO");
        }
      }
    }
    // console.log(answer);

    let finalAns = "NO";
    if (answer.includes("NO")) {
      finalAns = "NO";
    } else {
      finalAns = "YES";
    }
    console.log(finalAns); //I can see it on the console

    return finalAns; // this returns nothing
  }

  gridChallenge(gridOrig);
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It does return the result, you just don't use it. Try this:

const gridChallengeResult = gridChallenge(gridOrig); // saving returned value to variable
console.log(gridChallengeResult) // logging it to the console
about 4 years ago · Juan Pablo Isaza Relatório
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