Skip to content

Instantly share code, notes, and snippets.

@huiralb
Last active May 14, 2016 08:04
Show Gist options
  • Save huiralb/90f8293edf73a9c1cea8edaa93b01c92 to your computer and use it in GitHub Desktop.
Save huiralb/90f8293edf73a9c1cea8edaa93b01c92 to your computer and use it in GitHub Desktop.
Transpose Array
// 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