update utils

This commit is contained in:
MuslemRahimi 2024-12-10 18:16:54 +01:00
parent 13424c1dc3
commit 0900796a61

View File

@ -197,12 +197,11 @@ export const groupNews = (news, watchList) => {
export const calculateChange = (oldList?: any[], newList?: any[]) => { export const calculateChange = (oldList?: any[], newList?: any[]) => {
if (!oldList?.length || !newList?.length) return [...(oldList || [])]; if (!oldList?.length || !newList?.length) return [...(oldList || [])];
const newListMap = new Map(newList.map(item => [item.symbol, item])); const newListMap = new Map(newList.map((item) => [item.symbol, item]));
for (let i = 0, len = oldList.length; i < len; i++) { const updatedList = oldList.map((item) => {
const item = oldList[i];
const newItem = newListMap.get(item.symbol); const newItem = newListMap.get(item.symbol);
if (newItem?.avgPrice) { if (newItem?.avgPrice) {
const { price, changesPercentage } = item; const { price, changesPercentage } = item;
const newPrice = newItem.avgPrice; const newPrice = newItem.avgPrice;
@ -215,11 +214,14 @@ export const calculateChange = (oldList?: any[], newList?: any[]) => {
item.previous = price; item.previous = price;
item.price = newPrice; item.price = newPrice;
} }
}
return oldList; return item;
});
return updatedList;
}; };
export function updateStockList(stockList, originalData) { export function updateStockList(stockList, originalData) {
// Create a Map for O(1) lookup of original data by symbol // Create a Map for O(1) lookup of original data by symbol
const originalDataMap = new Map( const originalDataMap = new Map(