MCPcopy Create free account
hub / github.com/adobe/react-spectrum / cascadeRounding

Function cascadeRounding

packages/react-stately/src/table/TableUtils.ts:274–292  ·  view source on GitHub ↗
(flexItems: FlexItem[])

Source from the content-addressed store, hash-verified

272}
273
274function cascadeRounding(flexItems: FlexItem[]): number[] {
275 /*
276 Given an array of floats that sum to an integer, this rounds the floats
277 and returns an array of integers with the same sum.
278 */
279
280 let fpTotal = 0;
281 let intTotal = 0;
282 let roundedArray: number[] = [];
283 flexItems.forEach(function (item) {
284 let float = item.targetMainSize;
285 let integer = Math.round(float + fpTotal) - intTotal;
286 fpTotal += float;
287 intTotal += integer;
288 roundedArray.push(integer);
289 });
290
291 return roundedArray;
292}

Callers 1

calculateColumnSizesFunction · 0.85

Calls 1

pushMethod · 0.80

Tested by

no test coverage detected