File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -348,6 +348,17 @@ <h3>Persons:</h3>
348348 fill ( ) ;
349349}
350350
351+ function normalizeItem ( itemId ) {
352+ const item = data . items . find ( byId ( itemId ) ) ;
353+
354+ const sum = data . persons . map ( person => getAmount ( person , item ) ) . sum ( ) ;
355+ if ( sum === 0 ) {
356+ return ;
357+ }
358+ data . persons . filter ( person => itemId in person . amounts ) . forEach ( person => person . amounts [ itemId ] *= item . amount / sum ) ;
359+ fill ( ) ;
360+ }
361+
351362function personPaid ( personId , paid ) {
352363 data . persons . find ( byId ( personId ) ) . paid = paid ;
353364 fill ( ) ;
@@ -411,7 +422,8 @@ <h3>Persons:</h3>
411422 </div>` ) . join ( "\n" ) }
412423 <div class="flex">
413424 <button onclick="splitEqually(${ item . id } )">Split equally</button>
414- <button onclick="clearItem(${ item . id } )">Clear item</button>
425+ <button onclick="clearItem(${ item . id } )">Clear</button>
426+ <button onclick="normalizeItem(${ item . id } )">Normalize</button>
415427 <p class="itemPending"></p>
416428 </div>
417429 </div>` ) . join ( "\n" ) ;
You can’t perform that action at this time.
0 commit comments