Skip to content

Commit

Permalink
frequency: ensure --other-sorted works with --other-text
Browse files Browse the repository at this point in the history
and also replace unwrap() with more robust error-handling
  • Loading branch information
jqnatividad committed May 7, 2024
1 parent af4ecdb commit 7430ad7
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/cmd/frequency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,14 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
let mut sorted_counts: Vec<(Vec<u8>, u64, f64)> = args.counts(&ftab);

// if not --other_sorted and the first value is "Other (", rotate it to the end
if !args.flag_other_sorted && sorted_counts.first().unwrap().0.starts_with(b"Other (") {
if !args.flag_other_sorted
&& sorted_counts
.first()
.map(|(value, _, _)| {
value.starts_with(&format!("{} (", args.flag_other_text).as_bytes().to_vec())
})
.unwrap_or(false)
{
sorted_counts.rotate_left(1);
}

Expand Down

0 comments on commit 7430ad7

Please sign in to comment.