From 0900796a614738b8aa4f2e4b523eea41e32f1f1b Mon Sep 17 00:00:00 2001 From: MuslemRahimi Date: Tue, 10 Dec 2024 18:16:54 +0100 Subject: [PATCH] update utils --- src/lib/utils.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 88771253..df5e4613 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -197,12 +197,11 @@ export const groupNews = (news, watchList) => { export const calculateChange = (oldList?: any[], newList?: any[]) => { if (!oldList?.length || !newList?.length) return [...(oldList || [])]; - const newListMap = new Map(newList.map(item => [item.symbol, item])); - - for (let i = 0, len = oldList.length; i < len; i++) { - const item = oldList[i]; + const newListMap = new Map(newList.map((item) => [item.symbol, item])); + + const updatedList = oldList.map((item) => { const newItem = newListMap.get(item.symbol); - + if (newItem?.avgPrice) { const { price, changesPercentage } = item; const newPrice = newItem.avgPrice; @@ -215,11 +214,14 @@ export const calculateChange = (oldList?: any[], newList?: any[]) => { item.previous = price; item.price = newPrice; } - } - return oldList; + return item; + }); + + return updatedList; }; + export function updateStockList(stockList, originalData) { // Create a Map for O(1) lookup of original data by symbol const originalDataMap = new Map(