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

Function cascadeRounding

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

Source from the content-addressed store, hash-verified

258}
259
260function cascadeRounding(flexItems: FlexItem[]): number[] {
261 /*
262 Given an array of floats that sum to an integer, this rounds the floats
263 and returns an array of integers with the same sum.
264 */
265
266 let fpTotal = 0;
267 let intTotal = 0;
268 let roundedArray: number[] = [];
269 flexItems.forEach(function (item) {
270 let float = item.targetMainSize;
271 let integer = Math.round(float + fpTotal) - intTotal;
272 fpTotal += float;
273 intTotal += integer;
274 roundedArray.push(integer);
275 });
276
277 return roundedArray;
278}

Callers 1

calculateColumnSizesFunction · 0.85

Calls 1

pushMethod · 0.80

Tested by

no test coverage detected