The code below is converting: data from one format to another
# input sample
{
productText: [
{
"language": "en",
"version": "1",
"sequence": 1,
"text": "blah",
"textType": "ROMANCE"
}
]
}
# output sample
{
productText: [
{
sequence: 1,
textType: "ROMANCE"
text: [
{
text: "blah",
language: "en",
version: "1",
}
]
}
]
}
The source:
deserialize: (profileJSON)->
return profileJSON unless profileJSON.productText?
profileJSON.productText = _(profileJSON.productText).reduce(
(acc, el)->
current = _(acc).findWhere(
_(el).pick('sequence', 'textType')
)
unless current?
current = _(el).pick('sequence', 'textType')
current.text = []
acc.push(current)
current.text.push(
_(el).pick('version', 'text', 'language')
)
return acc
[]
)
return profileJSON
My colleague said that I overuse underscore. Is he right? Is it a good piece of code?