我不想在標題中有目的地模糊,我很抱歉。只是無法弄清楚解決這個問題的一個好的和簡潔的方法。解決複雜數組連接和分析的最優雅方法?
我正在構建一個應用程序,爲一組個人顯示他們在滾動28天內的位置。在視覺上(我不知道這一點),我們基本上是在討論一張桌子上最左邊一列的人物,28天頂部和表格單元格中的下落。
源數據由兩個列表構成(在SharePoint中)。在其中一個,他們記錄他們的「默認」位置。另一方面,他們表明他們將要在何時何地旅行。在任何情況下,我得到過的對象的數組是這樣的:
從下落列表:
[
{Date:'2017-05-25T00:00:00Z',EventLength:'Full Day',TeamMem:'Person McPerson',Title:'Public Holiday'},
//Lots more.
]
從默認位置列表:
[
{TeamMem:'Person McPerson',Location:'Main Office'}
]
我要弄清楚如何將所有這些結合在一起,這樣,對於每個人,我都有一組對象,在今天和今天+ 28天之間的任何一天給出該人的位置。有趣的一面是,他們插入行蹤清單的項目可能是全天或半天(PM或AM)。所以我也需要在這次合併中考慮半天。
TL; DR,我做的28天的陣列,使用下劃線的_.difference()函數查找的日子裏,每個團隊成員,那裏沒有下落項中添加的項背到指定默認位置的每個日期的行蹤陣列,然後做一件我幾乎可以跟隨的事情,我一年前處理半天的項目。
它的工作原理,但我知道這可能不是最優雅的方式來處理這個問題。有人有主意嗎?
編輯爲清楚起見
最後,我必須每人一個數組,一個爲我追蹤行蹤每天28個項目。在28天的時間段內,在今天和今天+28天之間,我應該有一些行蹤信息和一些默認位置,具體取決於團隊成員實際登錄系統的情況。
多個編輯
我可以對這個被說服,但我想最終的陣列需要看起來像這樣:
[
Person1 McPerson:[//Array of 28 events, either their whereabouts or defaults.],
Person2 McPerson:[//Array of 28 events, either their whereabouts or defaults.],
Person3 McPerson:[//Array of 28 events, either their whereabouts or default locations.],
//Etc, for however many people.
]
編輯額外的例子
希望這些澄清一點:
嘿,對不起,如果這不明確。我可能不需要日期。我使用日期來確定我是否有那天的下落。 – ChrisPEditor
我明白了。我稍微改變了代碼,因爲我假定數組的大小和相應的索引是相同的,這不一定是真的。請讓我知道這是否適合你。 – Sventies
嗯。我不能在普通數組上使用.find()。我將它轉換爲.filter(因爲我們只是過濾當前團隊成員的默認值),但是這仍然只是從行蹤列表中返回原來的10個左右的行蹤。 – ChrisPEditor