Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

183
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!