Skip to content

Commit

Permalink
add default sort in wasm
Browse files Browse the repository at this point in the history
sort weights in descending order
sort array of weights in descending order (standard olympic "greedy" method on top)
  • Loading branch information
jvogit committed Apr 8, 2024
1 parent 7c457e2 commit 61ace84
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions svelteww/src/lib/WeightCalculatorlatorForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@
{#each outWeights as weights}
<div>
<BarbellWeight
weights={weights.sort((a, b) => b - a)}
weights={weights}
weightPlateStyleMap={selectedWeightPlateSet.weightsStyle}
clipped={isClipWeightSelected}
/>
<div style="padding-top: 10px;">
{weights.sort((a, b) => b - a).map(weight => selectedWeightPlateSet.fmtWeightWithUnit(weight)).join(", ")}
{weights.map(weight => selectedWeightPlateSet.fmtWeightWithUnit(weight)).join(", ")}
</div>
</div>
{/each}
Expand Down
11 changes: 7 additions & 4 deletions wasmww/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mod utils;

use std::collections::{HashMap, HashSet};
use std::{cmp::Reverse, collections::{HashMap, HashSet}};
use wasm_bindgen::prelude::*;

type MinWeights = (usize, HashSet<Vec<usize>>);
Expand All @@ -24,9 +24,12 @@ impl MinWeightsOutput {

impl From<MinWeights> for MinWeightsOutput {
fn from(value: MinWeights) -> Self {
let mut weights: Vec<Vec<usize>> = value.1.into_iter().collect();
weights.sort_by(|a, b| b.cmp(a));

Self {
amt: value.0,
weights: value.1.into_iter().collect(),
weights,
}
}
}
Expand Down Expand Up @@ -55,7 +58,7 @@ pub fn what_weights_unlimited(
.into_iter()
.map(|mut v| {
v.push(*weight);
v.sort();
v.sort_by_key(|w| Reverse(*w));

v
})
Expand Down Expand Up @@ -102,7 +105,7 @@ pub fn what_weights_limited(
.into_iter()
.map(|mut v| {
v.push(*weight);
v.sort();
v.sort_by_key(|w| Reverse(*w));

v
})
Expand Down

0 comments on commit 61ace84

Please sign in to comment.