How can I obtain the max number of a JavaScript Array containing strings?
const array = ['a', 3, 4, 2] // should return 4
Here's my answer but I got NaN
function maxNum(arr) {
for(let i=0; i<arr.length; i++){
return Math.max.apply(Math, arr);
}
}
maxNum(array) //NaN
const maxNum = arr => Math.max(...arr.filter(e => typeof e === 'number'));