Skip to content

Commit

Permalink
reduce amount of apple movement for collect->sync, see #219
Browse files Browse the repository at this point in the history
  • Loading branch information
jbphet committed May 15, 2024
1 parent 861bb09 commit d28bcd6
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion js/fair-share/model/FairShareModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,11 @@ export default class FairShareModel extends SharingModel<Apple> {
this.getActivePlates().forEach( plate => {

_.times( plate.tableSnackNumberProperty.value, () => {
const apple = this.appleCollection.pop();

// Get an apple from the collection. The `shift` method is used here because it leads to better apple
// movement (shorter distances to travel) versus `pop`.
const apple = this.appleCollection.shift();

assert && assert( apple, 'there should be enough apples to put on the plates' );
plate.addSnackToTop( apple! );
} );
Expand Down Expand Up @@ -227,6 +231,8 @@ export default class FairShareModel extends SharingModel<Apple> {
);
}
} );

// Mark the collection as empty now that the apples have all been moved to plates.
this.appleCollection.length = 0;

// Any apples that were moved to the top are subsequently turned into fractional representations and distributed
Expand Down

0 comments on commit d28bcd6

Please sign in to comment.