Javascript 使用ramdajs将对象转换为对象数组

Javascript 使用ramdajs将对象转换为对象数组,javascript,functional-programming,ramda.js,Javascript,Functional Programming,Ramda.js,我正在写一个程序,在一个文件中数单词 假设对象如下所示: { I: 2, it: 4, that: 1 } 我想做到: [ { word: 'I', count: 2 }, { word: 'it', count: 4 }, { word: 'that', count: 1 } ] 我可以通过使用命令式编程来实现目标:循环对象 我查看文档和谷歌,但找不到适合的方法:( 谢谢这可以通过以下方式实现: 酷~顺便说一句,我应该如何学习ramdajs?除了官方网站,我找不

我正在写一个程序,在一个文件中数单词

假设对象如下所示:

{
  I: 2,
  it: 4,
  that: 1
}
我想做到:

[
  { word: 'I', count: 2 }, 
  { word: 'it', count: 4 }, 
  { word: 'that', count: 1 }
]
我可以通过使用命令式编程来实现目标:循环对象

查看文档和谷歌,但找不到适合的方法:(


谢谢

这可以通过以下方式实现:


酷~顺便说一句,我应该如何学习ramdajs?除了官方网站,我找不到任何资源,我也不能总是在这里问问题。网站非常活跃,那里的人非常有帮助。此外,Brian Lonsdorf为学习JavaScript函数式编程创建了许多精彩的资源。看看他的各种教程吧演讲、演讲和放映。
//    convert :: {a} -> [{ word :: String, count :: a }]
const convert = R.compose(R.map(R.zipObj(['word', 'count'])), R.toPairs);

convert({I: 2, it: 4, that: 1});
// => [{"count": 2, "word": "I"}, {"count": 4, "word": "it"}, {"count": 1, "word": "that"}]