• 0 Posts
  • 2 Comments
Joined 1 year ago
cake
Cake day: July 22nd, 2023

help-circle

  • force@lemmy.worldtoProgrammer Humor@lemmy.mlFind yourself
    link
    fedilink
    English
    arrow-up
    20
    arrow-down
    4
    ·
    edit-2
    1 year ago

    wtf kind of cursed programming language is this? JS? it’s so ugly, in no universe should a function look like that

    but obviously as a rust enjoyer i have to do it like

    fn max ⟨T: PartialOrd + Copy⟩(nums: ⁊[T]) -> Option⟨T⟩ {
        let mut greatest: ⁊T = ⁊nums[0];
        match nums.len() {
            0 => None,
            1 => Some(*greatest),
            _ => {
                for num in nums {
                    if num > greatest {
                        greatest = num;
                    }
                }
                Some(*greatest)
            }
        }
    }
    

    edit: lemmy formatting REALLY hates references and generics it seems… time to go back to medieval times