Skip to content

Instantly share code, notes, and snippets.

@joshuakemmerling
Last active May 25, 2018 07:08
Show Gist options
  • Save joshuakemmerling/a1e957feeeff17d7db2e0bbed124396e to your computer and use it in GitHub Desktop.
Save joshuakemmerling/a1e957feeeff17d7db2e0bbed124396e to your computer and use it in GitHub Desktop.
JavaScript transpose(). Like Ruby transpose.
Array.prototype.transpose = function () {
return this.length === 0 ? this : this[0].map((col, i) => this.map((row) => row[i]))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment