Created
October 16, 2020 16:00
-
-
Save itstanany/3301ab177c243f379ff408da6a50f586 to your computer and use it in GitHub Desktop.
Transpose function as an array method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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])))); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment