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

108
Views
Matrix transpose JS

Functions that output the transpose of a matrix - a new matrix where the columns and rows of the original are swapped. I'm trying to figure out why the second function outputs incorrect results?

function transpose(matrix) {
    let res = [];
    for(let i = 0;  i < matrix[0].length; i++) {
        res[i] = [];
        for(let j = 0;  j < matrix.length; j++) {
            res[i][j] = matrix[j][i];
        }
    }
    return res; 
}

function transpose(matrix) {
    let res = Array(matrix[0].length).fill([]);
    for(let i = 0;  i < res.length; i++) {
        for(let j = 0;  j < matrix.length; j++) {
            res[i][j] = matrix[j][i];
        }
    }
    return res; 
}
about 4 years ago · Juan Pablo Isaza
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!