我有一個日期數組,其中包含當前加上10天,我從數據庫中導入數組。我也有一個動物名字陣列。根據導入的內容,我想將動物名稱放置在過濾數組中的過濾數組中。例如:如何用另一個值替換正在更改的陣列?
date array: `[9, 10, 11, 12, 13, 14, 15, 16, 17, 18]`
imported date array from db: [9, 12, 14, 18]
imported animal name array from db: [dog, cat, tiger, sheep]
這就是我想要的過濾動物名看起來像
filtered animal name array: [dog, "", "", cat, "", tiger, "", "", "", sheep]
我知道我所提供的代碼是錯誤的,我覺得我incorretly接近這一點。我應該怎麼做?
for(var j = 0; j < self.arrayofweek.count; j++){
for(var t = 0; t < self.datesfromdb.count; t++){
if(self.date[t] == self.datearray[j]){
self.namefiltered[t] = self.tutorname[j]
print("filtered name \(self.namefiltered)")
}
}
}
怎麼樣的合併運算符:'字典[$ 0 ] ?? 「」'。 BTW爲'zip'函數+1,我現在沒有那個。 – FranMowinckel
謝謝,我沒有想到使用它。我相信它可以更短。在一行中創建字典會很好,但使用'reduce'創建數組或字典會降低性能。 – Eendje
如果我想對UIImage數組做同樣的操作,該怎麼辦? – stackerleet