Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Add new Transpose Array multidimensional in Javascript and upda… #437

Merged
merged 2 commits into from
Oct 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);