我无法显示代码的道歉,只是不确定该如何处理。
我想用分数实现类似display: flex/grid
的功能:
给出容器宽度:200px
项目:[0.5,1,50px]
我应该能够计算彼此之间的相对分数:
item1: 50 (half the size of item 2)
item2: 100 (double the size of item 1)
item3: 50 (static size not a fraction)
const totalSize = 900;
const items = [1,0.2,75,0.6,100];
const totalStaticSize = items.filter(n => n > 1).reduce((acc,n) => acc + n,0);
const derivedItems = items.map(item => {
if (item > 1) {
// A static value.
return item;
}
// How to calculate this fractional item relative to others?
return item;
});
console.log(derivedItems);