Last active
May 14, 2016 08:04
-
-
Save huiralb/90f8293edf73a9c1cea8edaa93b01c92 to your computer and use it in GitHub Desktop.
Transpose Array
This file contains 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
// transpose it | |
// @param Array values Array multidimension one row | |
// @Result Array | |
function transpose(values){ | |
return Object.keys(values[0]).map( function (columnNumber) { | |
return values.map( function (row) { | |
return row[columnNumber]; | |
}); | |
}); | |
} | |
// USAGE | |
var data = [ | |
['Ibrohim', 'Musa', 'Isa', 'Muhammad'] | |
]; | |
var result = transpose(data); | |
Console.log(result); | |
/* | |
* RESULT | |
[ | |
['Ibrohim'], | |
['Musa'], | |
['Isa'], | |
['Muhammad'] | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment