在ramda.js哪能組和字段排序列表,然後移動每個組的所有,但第一項到該項目的孩子嗎?Ramda組再轉換兄弟姐妹的孩子
如下面這裏,我的名字分組,並按日期排序下降:
[{ id: 1, name: 'bob', date: '2007-03-05', count: 15},
{ id: 2, name: 'bob', date: '2007-03-04', count: 32},
{ id: 3, name: 'bob', date: '2007-03-01', count: 27},
{ id: 4, name: 'jack', date: '2007-03-04', count: 3},
{ id: 5, name: 'jack', date: '2007-02-22', count: 5}]
進入
[{ id: 1, name: 'bob', date: '2007-03-05', count: 15,
children: [{ id: 2, name: 'bob', date: '2007-03-04', count: 32},
{ id: 3, name: 'bob', date: '2007-03-01', count: 27}]
},
{ id: 4, name: 'jack', date: '2007-03-04', count: 3,
children: [{ id: 5, name: 'jack', date: '2007-02-22', count: 5}]
}
]
我知道,我可以抓住與R.head整個列表的頂部項目其餘的與R.tail一起,然後把它作爲一個孩子與R.merge一起添加,但我不知道如何在列表中抓住一個組的頂部或尾部。
這太神奇了 –