# mat.maxElementInEachColumn()

{% tabs %}
{% tab title="💾 程式" %}
⬆️ 需要： [mat.transpose](mat.transpose "mention")

```javascript
// ⬆️ 需要： matrix.transpose()
import matrix_transpose from '../mixin/matrix_transpose.mjs';
Object.assign(Array.prototype, matrix_transpose);

/**
 * find max element in each column
 * @example
 * import matrix_maxElementInEachColumn from './matrix_maxElementInEachColumn.mjs';
 * Object.assign(Array.prototype, matrix_maxElementInEachColumn);
 */
const matrix_maxElementInEachColumn = {

    /**
     * find max element in each column
     * @example
     * let m = [[1, 5, 2],[2, 6],[3, 4, 5]]
     * m.maxElementInEachColumn()  // [ 3, 6, 5 ]
     * @return {[number]}
     */
    maxElementInEachColumn() {
        return this
            .transpose()                                        // see matrix in cols
            .map(col => Math.max(...col.removeUndefined()))     // max element in each col
    },

};

export default matrix_maxElementInEachColumn;
```
{% endtab %}

{% tab title="💈範例" %}
```javascript
import matrix_maxElementInEachColumn from '../objects/mixin/matrix_maxElementInEachColumn.mjs';
Object.assign(Array.prototype, matrix_maxElementInEachColumn);

let m = [[1, 5, 2], [2, 6], [3, 4, 5]];  
m.maxElementInEachColumn(),     // [ 3, 6, 5 ]
```
{% endtab %}

{% tab title="📘 手冊" %}
* JSDoc ⟩ [@requires](https://jsdoc.app/tags-requires.html)
{% endtab %}
{% endtabs %}
