Concatenating an array of arrays in Coffeescript

后端 未结 5 720

I\'m trying to find an elegant way in Coffeescript to merge an array of arrays, so that [[1,2,3],[4,5,6],[7,8,9]] ==> [1,2,3,4,5,6,7,8,9].

As you might imagine, I need t

5条回答
  •  深忆病人
    2021-02-04 01:00

    What about this for Coffee

    [[1, 2, 3], [4, 5, 6], [7, 8, 9]].reduce (a, b) ->
      a.concat b
    

    or this for pure Javascript

    [[1, 2, 3], [4, 5, 6], [7 , 8, 9]].reduce((a, b) => a.concat(b));
    

提交回复
热议问题