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

184
Visualizações
How to log [1, 2 ,3] and not [1.0,2.0,3.0] using Logger.log in Google Apps Script?

I'm trying to solve a programing puzzle/game. It's a Spiral Matrix and the result is correct but my array is outputting .0 at the end of my arrays.

For example, the input is

[1, 2, 3], 
[4, 5, 6], 
[7, 8, 9]

The output is

[1.0,2.0,3.0,6.0,9.0,8.0,7.0,4.0,5.0]

But I'm looking for

[ 1, 2, 3, 6, 9, 8, 7, 4, 5]

The code I am using is from the YouTube video "LeetCode 54 Spiral Matrix in javascript".

How do I Logger.log(result) without the .0?

function myFunction() {
  matrix = [
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9]
  ];
  // result array
  const result = [];
  // boundry varibals
  let left = 0;
  let top = 0;
  let right = matrix[0].length - 1;
  let bottom = matrix.length - 1;
  // starting direction clock wise
  let direction = 'right';
  // start loop
  while (left <= right && top <= bottom) {

    if (direction === 'right') {
      for (let i = left; i <= right; i += 1) {
        result.push(matrix[top][i]);
      }
      top += 1;
      direction = 'down';
    } else if (direction === 'down') {
      for (let i = top; i <= bottom; i += 1) {
        result.push(matrix[i][right]);
      }
      right -= 1;
      direction = 'left';
    } else if (direction === 'left') {
      for (let i = right; i >= left; i -= 1) {
        result.push(matrix[bottom][i]);
      }
      bottom -= 1;
      direction = 'up';
    } else if (direction === 'up') {
      for (let i = bottom; i >= top; i -= 1) {
        result.push(matrix[i][left]);

      }

      left += 1;
      direction = 'right';
    }
  }
  Logger.log(result);
  return result;
}

I'm using google-apps-script.

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Add JSON.stringify() to your output.

Logger.log(JSON.stringify(result));

Output:

enter image description here

Reference:

  • JSON.stringify()
about 4 years ago · Santiago Trujillo 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