Concatenating an array of arrays in Coffeescript

后端 未结 5 715

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 00:56

    Just use the JS idiom:

     [].concat.apply([], a)
    

    which becomes a little nicer in Coffee:

    $ coffee -e 'a = [[1,2,3],[4,5,6],[7,8,9]]; console.dir [].concat a...'
    [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
    

提交回复
热议问题