Skip to content

Instantly share code, notes, and snippets.

View itstanany's full-sized avatar
🎯
Focusing

Tanany itstanany

🎯
Focusing
View GitHub Profile
@itstanany
itstanany / transpose.js
Created October 16, 2020 16:00
Transpose function as an array method
// one line transpose array
// iterate over th elements of the first arra to dtermine the number of rows in the new array
// then iterate over the arrays of the original parent array to determine the number of columns and add the new values to the created array(s)
Array.prototype.Transpose = function() {
return this[0].map((elem1, indx1) => (this.map((elem2) => (elem2[indx1]))));
}