update utils
This commit is contained in:
parent
13424c1dc3
commit
0900796a61
@ -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(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user