Skip to content

Instantly share code, notes, and snippets.

@xavierchow
Created April 12, 2015 08:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xavierchow/342be76041980e36e663 to your computer and use it in GitHub Desktop.
Save xavierchow/342be76041980e36e663 to your computer and use it in GitHub Desktop.
groupArray
_ = require 'lodash'
input = [
[{"name":"123","url":"fdsfds","type":"x"},{"name":"123","url":"fdsfds","type":"y"},{"name":"123","url":"fdsfds","type":"z"}],
[{"name":"123","url":"fdsfds","type":"x"},{"name":"123","url":"fdsfds","type":"y"}]
]
flattened = _.flatten(input)
grouped = _.groupBy flattened, (obj) ->
return obj.type
nestedArr = _.map grouped, (v) ->
return v
console.log nestedArr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment