Skip to content

Commit

Permalink
Merge pull request #437 from kevadamar/master
Browse files Browse the repository at this point in the history
Feat: Add new Transpose Array multidimensional in Javascript and upda…
  • Loading branch information
fineanmol committed Oct 2, 2021
2 parents 2d0f13b + 11f9e03 commit 36bee6b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Contributors.html
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,7 @@
<a class="box-item" href="https://github.com/Shyam-2001"><span>Shyam Gupta</span></a>
<a class="box-item" href="https://github.com/yamini236"><span>Yamini Bansal</span></a>
<a class="box-item" href="https://github.com/whatiskeptiname"><span>Susan Ghimire</span></a>

<a class="box-item" href="https://github.com/NitulKalita"><span>Nitul</span></a>
<a class="box-item" href="https://github.com/jash-kothari"><span>Jash Kothari</span></a>
<a class="box-item" href="https://github.com/SimonUR"><span>Simon</span></a>
Expand All @@ -586,7 +587,7 @@
<a class="box-item" href="https://github.com/ahad-abd"><span>Abdul Ahad</span></a>
<a class="box-item" href="https://github.com/MFR414/"><span>M Firmansyah Rifai</span></a>
<a class="box-item" href="https://github.com/AdityaSawant21"><spann>Aditya Sawant</span></a>

<a class="box-item" href="https://github.com/kevadamar"><spann>Keva Damar Galih</span></a>


<!-- Please maintain the alignment... -->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
function transpose(array) {
let height = array.length;
let width = array[0] instanceof Array ? array[0].length : 0;
let arrTranspose = [];

if (height == 0 || width == 0) return 'Data is not a multidimensional array';

for (let i = 0; i < height; i++) {
arrTranspose[i] = [];
for (let j = 0; j < width; j++) {
arrTranspose[i][j] = array[j][i];
}
}
return arrTranspose;
}

const input = [
[1, 2, 3],
[1, 2, 3],
[1, 2, 3],
];

transpose(input);

0 comments on commit 36bee6b

Please sign in to comment.