I have an array of arrays and I would like to find the max value of the first elements in those arrays.
Example:
[ [ 300, 600 ], [ 160, 600 ], [ 120, 600 ] ]
This example should return 300 because it is the max value of 300, 160 and 120.
This is an easy task and can be solved like this:
let first = array.map(item => item[0]);
let max = Math.max(...first); // max == 300
The problem is that I work with TypeScript and this array potentially can have a fixed string in it like so:
[ 'something' ]
No matter what I try to do I get errors from different places. For example I try something like this:
array.filter(item => item != "something").map(item => item[0]);
I cannot change the original array. So how can I overcome this issue with TypeScript? Thanks for help.