Created
April 12, 2015 08:24
-
-
Save xavierchow/342be76041980e36e663 to your computer and use it in GitHub Desktop.
groupArray
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_ = 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