Here you can find the source of transpose()
/*!/* ww w .j a va 2 s .co m*/ * Prototype and jQuery plugin to transpose Array. * * @author Shamasis Bhattacharya * @link http://www.shamasis.net/ * @email mail@shamasis.net * * @version 1.0.0.0 * @publish 24-Feb-2010 00:00 +0530 IST * */ /** * Transposes a given array. * @id Array.prototype.transpose * @author Shamasis Bhattacharya * @type Array * @return The Transposed Array * @compat=ALL */ Array.prototype.transpose = function() { // Calculate the width and height of the Array var a = this, w = a.length ? a.length : 0, h = a[0] instanceof Array ? a[0].length : 0; // In case it is a zero matrix, no transpose routine is needed. if(h === 0 || w === 0) { return []; } /** * @var {Number} i Counter * @var {Number} j Counter * @var {Array} t Is the array where transposed data is stored. */ var i, j, t = []; // Loop through every item in the outer array (height) for(i=0; i<h; i++) { // Insert a new row (array) t[i] = []; // Loop through every item per item in outer array (width) for(j=0; j<w; j++) { // Save transposed data. t[i][j] = a[j][i]; } } return t; };
Array.prototype.transpose = function() { var a = this, w = a.length ? a.length : 0, h = a[0] instanceof Array ? a[0].length : 0; if(h === 0 || w === 0) { return []; } var i, j, t = []; for(i=0; i<h; i++) { t[i] = []; for(j=0; j<w; j++) { ...
"use strict"; Array.prototype.transpose = function (){ const columns = []; for( let i = 0; i < this[0].length; i++){ columns.push([]); for( let i = 0; i < this.length; i++){ for(let j = 0; j < this.length; j++){ columns[j].push(this[i][j]); ...
Array.prototype.transpose = function() { var a = this, w = a.length ? a.length : 0, h = a[0] instanceof Array ? a[0].length : 0; if(h === 0 || w === 0) { return []; } var i, j, t = []; for(i=0; i<h; i++) { t[i] = []; for(j=0; j<w; j++) { ...
Array.prototype.transpose = function (){ const cols = this[0].length; const rows = this.length; let result = Array(rows).fill().map(() => Array()); this.forEach(function (row){ row.forEach(function (num, index){ result[index].push(num); }); }); ...
Array.prototype.transpose = function() { var result = []; if (!(this instanceof Array)) return result; if (this.length == 0) return result; ...