diff --git a/src/lib/utils.ts b/src/lib/utils.ts index df5e4613..61e3d56d 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -198,8 +198,10 @@ export const calculateChange = (oldList?: any[], newList?: any[]) => { if (!oldList?.length || !newList?.length) return [...(oldList || [])]; const newListMap = new Map(newList.map((item) => [item.symbol, item])); + const updatedList = []; - const updatedList = oldList.map((item) => { + for (let i = 0; i < oldList.length; i++) { + const item = oldList[i]; const newItem = newListMap.get(item.symbol); if (newItem?.avgPrice) { @@ -215,13 +217,14 @@ export const calculateChange = (oldList?: any[], newList?: any[]) => { item.price = newPrice; } - return item; - }); + updatedList.push(item); + } return updatedList; }; + export function updateStockList(stockList, originalData) { // Create a Map for O(1) lookup of original data by symbol const originalDataMap = new Map(