一個陣列我有2個陣列xDates
和yMentions
創建從2個陣列連鍵X和Y
xDates
[1453766400000, 1453852800000, 1453939200000...
yMentions
[5160, 5240, 7090...
目標就像是一個數組所以:
[
{
x: 1453766400000,
y: 5160
},
...
]
試圖用Ramda Zip認爲zipObj會是什麼,我需要,但下面只產生1個對象:
R.zipObj(['x', 'x', 'x'], [1, 2, 3]);
=>{"x": 3}
想通了,也許我在x,然後在y運行R.zipObj數組,然後壓縮在一起然後設置爲數組下面mentionsPointsArray
:
const createMentionPoints = (frequencyPoints, termsData) => {
const yMentions = termsData.mentions;
const propX = R.prop('x');
const xPointsFromFrequency = R.map(propX, frequencyPoints);
console.log('xDates', xPointsFromFrequency)
console.log('yMentions', yMentions)
const mentionsPointsArray = []
return frequencyPoints;
};
謝謝!剛剛計算出了Ramda解決方案。在我們的應用中大量使用Ramda,因爲它使事情變得更加簡單,將選擇這個併發布我剛發現的關於zipWith的內容。 –