修复:补充提交课程与图书选择商品公共组件价格处理
This commit is contained in:
@@ -56,4 +56,22 @@ export const copyToClipboard = (content: string, title: string = '') => {
|
||||
console.error('复制失败:', error)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算最低价格
|
||||
*/
|
||||
export const calculateLowestPrice = (priceData: object): { key: string, value: number } => {
|
||||
const validEntries = Object.entries(priceData)
|
||||
.filter(([, value]) => typeof value === 'number' && value !== 0);
|
||||
|
||||
if (validEntries.length === 0) {
|
||||
throw new Error('No valid non-zero price found in the data');
|
||||
}
|
||||
|
||||
const [minKey, minValue] = validEntries.reduce((min, curr) =>
|
||||
curr[1] < min[1] ? curr : min
|
||||
);
|
||||
|
||||
return { key: minKey, value: minValue };
|
||||
}
|
||||
Reference in New Issue
Block a user