fn most_slept_min(shed: &GuardSchedule) -> Option<MinFreq> {
  let mut occurances = [0u8; 60];
  for i in &shed.sleep_interval {
    (i.0..i.1).for_each(|i| occurances[i as usize] += 1);
  }
  // https://stackoverflow.com/a/58103194/183120
  let max_idx = occurances
    .iter()
    .enumerate()
    .max_by_key(|(_idx, &val)| val) // find max by val
    .map(|(idx, _val)| idx); // but obtain idx as result
  if let Some(idx) = max_idx {
    return Some(MinFreq(idx as u8, occurances[idx]));
  }
  None
}
/// Returns the most slept minute with frequency
Returns the most slept minute with frequency
Returns the most slept minute with frequency
fn most_slept_min(shed: &GuardSchedule) -> Option<MinFreq> {
  let mut occurances = [0u8; 60];
  for i in &shed.sleep_interval {
    (i.0..i.1).for_each(|i| occurances[i as usize] += 1);
  }
  // https://stackoverflow.com/a/58103194/183120
  let max_idx = occurances
    .iter()
    .enumerate()
    .max_by_key(|(_idx, &val)| val) // find max by val
    .map(|(idx, _val)| idx); // but obtain idx as result
  if let Some(idx) = max_idx {
    return Some(MinFreq(idx as u8, occurances[idx]));
  }
  None
}
fn most_slept_min ( shed : & GuardSchedule ) -> Option < MinFreq > { let mut occurances = [ 0u8 ; 60 ] ; for i in & shed . sleep_interval { ( i . 0 .. i . 1 ) . for_each ( | i | occurances [ i as usize ] += 1 ) ; } // https://stackoverflow.com/a/58103194/183120 let max_idx = occurances . iter ( ) . enumerate ( ) . max_by_key ( | ( _idx , & val ) | val ) // find max by val . map ( | ( idx , _val ) | idx ) ; // but obtain idx as result if let Some ( idx ) = max_idx { return Some ( MinFreq ( idx as u8 , occurances [ idx ] ) ) ; } None }
Returns the most slept minute with frequency
Returns the most slept minute with frequency
shed
&GuardSchedule