How to find the max/min of a nested array in javascript?

前端 未结 6 1604
情歌与酒
情歌与酒 2020-12-08 01:04

I want to find the maximum of a nested array, something like this:

a = [[1,2],[20,3]]
d3.max(d3.max(a)) // 20

but my array contains a text

6条回答
  •  悲&欢浪女
    2020-12-08 01:36

    You can flatten an array and apply a function to each member

    Array.prototype.flatten= function(fun){
        if(typeof fun!= 'function') fun= '';
        var A= [], L= this.length, itm;
        for(var i= 0; i

提交回复
热议问题